Skip to content

Instantly share code, notes, and snippets.

@fmder
Created January 26, 2016 20:52
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fmder/494aaa2dd6f8c428cede to your computer and use it in GitHub Desktop.
Inflate a flattened dictionary
def inflate(d, sep="_"):
items = dict()
for k, v in d.items():
keys = k.split(sep)
sub_items = items
for ki in keys[:-1]:
try:
sub_items = sub_items[ki]
except KeyError:
sub_items[ki] = dict()
sub_items = sub_items[ki]
sub_items[keys[-1]] = v
return items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment