Here is an example:
This is a JSON file with some data in it:
{
"planet": {
"earth": {
"male": {
"amount": 9,
"young": 6,
"old": 3
},
"female": {
"amount": 12,
"young": 8,
"old": 4
}
}
}
}
Too many brackets but do not let that intimidate you. If I use the following code:
for item in data["earth"]["gender"]["male"]:
print(item)
I get this output which is expected:
amount
young
old
but what happened to the values? like, "amount" should be 9 and "young" should be 6 too. So while iterating through the dictionary, we printed ITEM which was "amount", "young" and "old". But if i wanted the output to look like this instead:
amount
9
young
6
old
3
What would we do? Can we do something like this? :
for item in data["earth"]["gender"]["male"]:
print(item)
print(item.value)
How do I grab the items and keys of the dictionary? Would appreciate some help, Thanks