Skip to content

Instantly share code, notes, and snippets.

@melvinkcx
Created June 30, 2019 06:27
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 melvinkcx/066406a777134a747b3538c1a39104cc to your computer and use it in GitHub Desktop.
Save melvinkcx/066406a777134a747b3538c1a39104cc to your computer and use it in GitHub Desktop.
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