You can use any:
>>> mylist = [1, 2, 3]
>>> any(x > 4 for x in mylist)
False
>>> any(x % 2 == 0 for x in mylist)
True
if any(my_condition(x) for x in mylist):
....
NOTE. Using the expression generator instead of understanding the list, you do not need to evaluate all the elements.
source
share