How do I find an object in a sequence satisfying a particular criterion?
List comprehension and filter go through the entire list. Is the only alternative a handmade
Actually, in Python 3, at least, filter doesn't go through the entire list.
To double check:
def test_it(x): print(x) return x>10 var = next(filter(test_it, range(20)))
In Python 3.2, that prints out 0-11, and assigns var to 11.
In 2.x versions of Python you may need to use itertools.ifilter.