poros
10/4/2015 - 1:31 PM

Check if at least one element satisfies a condition

Check if at least one element satisfies a condition

for x in numbers:
    if x % 2 == 0:
        return True
return False

any(x % 2 == 0 for x in numbers)
# it's a generator, stops at the first occurrence