Skip to content

Instantly share code, notes, and snippets.

@oss6
Created March 25, 2015 21:20
Show Gist options
  • Save oss6/df73a464fa9420343ca6 to your computer and use it in GitHub Desktop.
Save oss6/df73a464fa9420343ca6 to your computer and use it in GitHub Desktop.
Gets the value of a nested dictionary specified by the path
def get_prop(d, path):
"""
Gets the value of a nested dictionary specified by the path
d: the dictionary to search recursively
path: a string path
"""
if d is None or not isinstance(d, dict) or not path:
return d
path = path.split('.')
ht = path[0], path[1:]
return get_prop(d.get(ht[0]), '.'.join(ht[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment