find
find
takes two arguments, the first being a list and the second being a function. The function must contain the keyword key
and must return a bool
. The first value found in the list that causes the function to return True
will be returned.
def key_fn(key=''):
return key['name'] == 'Bob'
return find(
[{'name': 'John'}, {'name': 'Bob'}, {'name': 'Charles'}],
key_fn) # {'name': 'Bob'}