标记为重复的示例不涉及嵌套字典。虽然我尝试了使用duplicate
的{{1}}中的示例,但它要么collections.OrderedDict()
,要么根本不打印任何内容。
数据与此类似:
list index out of range
这是我用来检索前四个数据并将其存储在结果列表中的代码。
[ {
"name":"frog",
"age":33,
"color":"green",
"weight":86,
"can_jump": true,
--- other data and so on ---
},
{
-- other data too ---
}
]
但是当我打印出决赛时,
结果它们随机显示,例如
i = 0
while i < len(data_file):
key = ["name", "age", "color", "weight"]
results = []
for x in data_file[i]:
results.append(data_file[i][x])
j = 0
while j < 4:
print("{}: {}".format(key[j], results[j]))
j+=1
print()
i+=1