Created
February 1, 2012 06:27
-
-
Save hidsh/1715483 to your computer and use it in GitHub Desktop.
python: sample of fiter and lambda
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
def even(x): | |
return x % 2 == 0 | |
l = range(0, 10) | |
print filter(even, l) | |
print filter(lambda x: x % 2, l) # odd() | |
# result | |
# [0, 2, 4, 6, 8] | |
# [1, 3, 5, 7, 9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment