Skip to content

Instantly share code, notes, and snippets.

@cmac1000
Created February 23, 2015 14:35
Show Gist options
  • Save cmac1000/265d3bc1add8dd5e404e to your computer and use it in GitHub Desktop.
Save cmac1000/265d3bc1add8dd5e404e to your computer and use it in GitHub Desktop.
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