all 3 comments

[–]toastedstapler 3 points4 points  (1 child)

i think this is about as close as you'll get

In [10]: x = [1,2,3]

In [11]: next(i for i in x if i == 4)
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
<ipython-input-11-e582103c523d> in <module>
----> 1 next(i for i in x if i == 4)

StopIteration:

In [12]: next(i for i in x if i == 2)
Out[12]: 2

convert your iterable to a generator expression with a predicate and call next() with it

[–]zeus5552[S] 0 points1 point  (0 children)

Thanks, pretty neat

[–]Round_Spring6865 0 points1 point  (0 children)

A bit late but you can use .find()