The example marked as duplicate does not address nested dictionaries. Although i tried the example in the duplicate
that uses collections.OrderedDict()
but it either gave list index out of range
or doesnt print anything at all.
The data looks similar to this:
[ {
"name":"frog",
"age":33,
"color":"green",
"weight":86,
"can_jump": true,
--- other data and so on ---
},
{
-- other data too ---
}
]
and here is the code i used to retrieve the first four data and store it in the results list.
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
but when i print out the final ,
results they display randomly like e.g.
name: 33
age:86
color: true
weight: green