Last active
August 11, 2016 05:11
-
-
Save jackeyGao/92370ada79868abe3d5f4ec1c19f8f6f to your computer and use it in GitHub Desktop.
Python 树状字典
This file contains 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
{ | |
"A": { | |
"AA": { | |
"AAA": "Hello" | |
} | |
}, | |
"B": { | |
"BB": { | |
"BBB": "world" | |
} | |
} | |
} |
This file contains 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
import json | |
from collections import defaultdict | |
d = defaultdict(lambda: defaultdict(tree)) | |
d["A"]["AA"]["AAA"] = "Hello" | |
d["B"]["BB"]["BBB"] = "world" | |
print(json.dumps(d, indent=2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment