Skip to content

Instantly share code, notes, and snippets.

@poros
Created October 4, 2015 13:31
Show Gist options
  • Save poros/2f0fa1927cf7c784603d to your computer and use it in GitHub Desktop.
Save poros/2f0fa1927cf7c784603d to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment