1
congeec 2017-10-31 17:31:09 +08:00
这在 PHP 里叫多维数组?在其他语言里叫 Dictionary, Map, Associative Array。
看 defaultdict https://docs.python.org/3/library/collections.html#collections.defaultdict |
2
CSM 2017-10-31 17:38:24 +08:00 1
from collections import defaultdict
import json def tree(): """ Factory that creates a defaultdict that also uses this factory """ return defaultdict(tree) root = tree() root['Page']['Python']['defaultdict']['Title'] = 'Using defaultdict' root['Page']['Python']['defaultdict']['Subtitle'] = 'Create a tree' root['Page']['Java'] = None print(json.dumps(root, indent=4)) 运行结果如下: { "Page": { "Python": { "defaultdict": { "Subtitle": "Create a tree", "Title": "Using defaultdict" } }, "Java": null } } https://segmentfault.com/a/1190000010280700 |
3
Va1n3R 2017-10-31 17:44:24 +08:00
这还繁琐吗...你没用过 C/C++吧,不对,这貌似就是 PHP 的 feature 吧...不觉得很危险吗
|