Created
October 4, 2015 13:31
-
-
Save poros/2f0fa1927cf7c784603d to your computer and use it in GitHub Desktop.
Check if at least one element satisfies a condition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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