Skip to content

Instantly share code, notes, and snippets.

@JimHaughwout
Created July 11, 2015 15:17
Show Gist options
  • Save JimHaughwout/86861ea8466163ecc0fe to your computer and use it in GitHub Desktop.
Save JimHaughwout/86861ea8466163ecc0fe to your computer and use it in GitHub Desktop.
TryExcept Dict Element Extract
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