#python – Find object in list that has attribute equal to some value (that meets any condition) Techhelpnotes
Explore tagged Tumblr posts
techhelpnotes · 3 years ago
Text
python – Find object in list that has attribute equal to some value (that meets any condition)
This gets the first item from the list that matches the condition, and returns None if no item matches. Its my preferred single-expression form.
However,
The naive loop-break version, is perfectly Pythonic — its concise, clear, and efficient. To make it match the behavior of the one-liner:
0 notes