Created
March 11, 2020 22:39
-
-
Save scooby/2063bbb6dfab8766d3aff55a7eba516f to your computer and use it in GitHub Desktop.
A straightforward way to handle missing keys.
This file contains hidden or 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
| try: | |
| val = my_dict[key] | |
| except KeyError: | |
| handle_missing_value(key) | |
| else: | |
| normal_logic(key, val) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment