Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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]:
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
You can’t perform that action at this time.