Skip to content

Instantly share code, notes, and snippets.

@melvinkcx
Created June 30, 2019 06:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Filtering Dictionary in Python
"""
Solution #1: Create a shallow copy of dict
"""
coffees = get_menu() # I use this function to generate my dict object
coffee_copy = {**coffees} # Create a shallow copy
for code, details in coffee_copy.items():
if details.get("sugar_free") is True:
del coffees[code]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment