Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

find element in list that matches a condition

#In Python 2.6 or newer:

#If you want StopIteration to be raised if no matching element is found:
next(x for x in the_iterable if x > 3)
#If you want default_value (e.g. None) to be returned instead:
next((x for x in the_iterable if x > 3), default_value)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #find #element #list #matches #condition
ADD COMMENT
Topic
Name
9+2 =