Created
July 8, 2015 10:56
-
-
Save white-gecko/595b22e9e8f3e0d12667 to your computer and use it in GitHub Desktop.
Python Default Dictionary of Dictionaries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
from collections import defaultdict | |
def ddict (): | |
return defaultdict(ddict) | |
def ddict2dict(d): | |
for k, v in d.items(): | |
if isinstance(v, dict): | |
d[k] = ddict2dict(v) | |
return dict(d) | |
myddict = ddict() | |
myddict["a"]["b"]["c"] = "value" | |
print(myddict) | |
mydict = ddict2dict(myddict) | |
print(mydict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment