Python: find object in list
November 15, 2009 21:56:19 Last update: November 15, 2009 21:57:59
Python doesn't seem to have a built-in function to find an object in a list that satisfies a specified criterion, for example, making a function
To find
This is not a lot of code, but it's not terse enough as you would expect of Python. Some suggestions are offered here:
f to return True.
To find
jack among people:
jack = None for p in people: if p.first_name == 'Jack': jack = p break
This is not a lot of code, but it's not terse enough as you would expect of Python. Some suggestions are offered here: