Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Filtering Dictionary in Python
"""
Solution #3: Deferred Update
Risk: What if an Exception is raised half way?
"""
coffees = get_menu()
keys_to_be_removed = []
for code, details in coffees.items():
if details.get("sugar_free") is True:
keys_to_be_removed.append(code)
for k in keys_to_be_removed:
del coffees[k]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.