Skip to content

Instantly share code, notes, and snippets.

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