Use generator comprehensions.
If you want to find one and just one element or
default argument in call for
next, it won’t raise
StopIteration if the item was not found in the list:
first_or_default = next((x for x in lst if ...), None)
You must log in to post a comment.