Created
June 30, 2019 06:37
-
-
Save melvinkcx/6ec13e00dbcd453d120e173a2338e457 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 #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