Created
June 30, 2019 06:27
-
-
Save melvinkcx/066406a777134a747b3538c1a39104cc to your computer and use it in GitHub Desktop.
Filtering Dictionary in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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