Skip to content

Instantly share code, notes, and snippets.

@melvinkcx
Created June 30, 2019 06:33
Show Gist options
  • Save melvinkcx/c42d402bb8d510ad80e002478a6e8131 to your computer and use it in GitHub Desktop.
Save melvinkcx/c42d402bb8d510ad80e002478a6e8131 to your computer and use it in GitHub Desktop.
Filtering Dictionary In Python 3
"""
Solution #2: Create a copy of keys
"""
coffees = get_menu()
key_copy = tuple(coffees.keys()) # Feel free to use any iterable collection
for k in key_copy:
if coffees[k].get("sugar_free") is True:
del coffees[k]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment