Steve Holden <[EMAIL PROTECTED]> writes:
> >    max(i for i,t in enumerate(x) if t <= y)
> > Those are actually pretty direct.
> 
> How about a solution (like the bisect one suggested almost as soon as
> this thread started) that doesn't iterate over the whole list.

Here's a Haskell-inspired one:

    len(list(itertools.takewhile(lambda t: y > t, x)))

It stops iterating when it hits an element >= y.  I originally wanted
to write the above as:
    
    len(itertools.takewhile(y.__gt__, x))

but it looks like regular numbers only support __cmp__ and not rich
comparison, and also you can't take the length of an iterator.  In
Haskell this type of thing is very natural:

   length(takeWhile (y >) x)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to