LoginSignup
0
1

More than 5 years have passed since last update.

Pythonでfind

Posted at
def find(lst, predicate):
  return next( (ele for ele in lst if predicate(ele)), None)

find([1,2,3], lambda n:n == 2)
# => 2
find([1,2,3], lambda n:n == 10000)
# => None
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1