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