Skip to content

Instantly share code, notes, and snippets.

@jherrlin
Created August 11, 2016 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jherrlin/8710afcecd9dfceab927360851bef64e to your computer and use it in GitHub Desktop.
Save jherrlin/8710afcecd9dfceab927360851bef64e to your computer and use it in GitHub Desktop.
from pprint import pprint as pp # Good looking print
animals = [
{'name': 'Fluffykins', 'species': 'rabbit'},
{'name': 'Caro', 'species': 'dog'},
{'name': 'Hamilton', 'species': 'dog'},
{'name': 'Harold', 'species': 'fish'},
{'name': 'Ursula', 'species': 'cat'},
{'name': 'Jimmy', 'species': 'fish'}
]
dogs_filter = filter(lambda x: x['species'] == 'dog', animals) # Do the filtering
print(type(dogs_filter)) # Print type
pp(list(dogs_filter)) # Convert to list and print items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment