Created
February 23, 2015 14:35
-
-
Save cmac1000/265d3bc1add8dd5e404e to your computer and use it in GitHub Desktop.
This file contains 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 is_a_cat(animal_name): | |
if animal_name == 'cat': | |
return True | |
else: | |
return False | |
def lycanthropize(animal_name): | |
return "were-" + animal_name | |
animals = ['cat', 'dog', 'bird'] | |
# filter a sequence | |
filtered = list(filter(is_a_cat, animals)) | |
print(filtered) # ['cat'] | |
# map a sequence | |
werebeasts = list(map(lycanthropize, animals)) | |
print(werebeasts) # ['were-cat', 'were-dog', 'were-bird'] | |
# pipeline | |
werecats = list(map(lycanthropize, filter(is_a_cat, animals))) | |
print(werecats) # ['were-cat'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment