Use a lambda function.
Let's say you have an array:
nums = [0,1,5]
Check whether 5 is in nums
in Python 3.X:
(len(list(filter (lambda x : x == 5, nums))) > 0)
Check whether 5 is in nums
in Python 2.7:
(len(filter (lambda x : x == 5, nums)) > 0)
This solution is more robust. You can now check whether any number satisfying a certain condition is in your array nums
.
For example, check whether any number that is greater than or equal to 5 exists in nums
:
(len(filter (lambda x : x >= 5, nums)) > 0)