Skip to content

Instantly share code, notes, and snippets.

@Fifan31
Created February 21, 2018 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fifan31/2b686852ef5c77da85989a9a13f74460 to your computer and use it in GitHub Desktop.
Save Fifan31/2b686852ef5c77da85989a9a13f74460 to your computer and use it in GitHub Desktop.
class DottedKeyDict(dict):
def get(self, path, default = None):
keys = path.split(".")
val = None
for key in keys:
if val:
if isinstance(val, list):
val = [ v.get(key, default) if v else None for v in val]
else:
val = val.get(key, default)
else:
val = dict.get(self, key, default)
if not val:
break;
return val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment