Created
July 11, 2015 15:17
-
-
Save JimHaughwout/86861ea8466163ecc0fe to your computer and use it in GitHub Desktop.
TryExcept Dict Element Extract
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
def try_dict_extract(dictionary, key_list): | |
""" | |
Iterates through a list of nested keys to try to return a dictionary key value. | |
On exception, returns NoneType | |
""" | |
try: | |
x = dictionary | |
for key in key_list: | |
x = x[key] | |
return x | |
except: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment