Python/gloss python nested dictionaries
来自菜鸟教程
<languages />
Python嵌套字典
嵌套词典
词典也可以包含许多词典,这被称为嵌套词典。
例
创建一个包含三个词典的字典:
myfamily = { "child1" : { "name" : "Emil", "year" : 2004 }, "child2" : { "name" : "Tobias", "year" : 2007 }, "child3" : { "name" : "Linus", "year" : 2011 } }
或者,如果您想嵌套三个已经作为字典存在的字典:
例
创建三个字典,然后创建一个包含其他三个字典的字典:
child1 = { "name" : "Emil", "year" : 2004 } child2 = { "name" : "Tobias", "year" : 2007 } child3 = { "name" : "Linus", "year" : 2011 } myfamily = { "child1" : child1, "child2" : child2, "child3" : child3 }