find element in list that matches a condition

Solutions on MaxInterview for find element in list that matches a condition by the best coders in the world

showing results for - "find element in list that matches a condition"
Lucia
08 Sep 2016
1#In Python 2.6 or newer:
2
3#If you want StopIteration to be raised if no matching element is found:
4next(x for x in the_iterable if x > 3)
5#If you want default_value (e.g. None) to be returned instead:
6next((x for x in the_iterable if x > 3), default_value)