I am trying to collect information from nested dictionaries (downloaded from json). I am trying to do this with a loop. I could not get the dictionary in the dictionary called "players". "players" contain a dictionary with the names of players and their identifiers. I would like to extract this dictionary. You can find my code and sample data below.
I managed to sort out the first level into a dictionary, but I canโt filter out the deeper levels.
I looked at other similar questions, but they solved different problems of dictionary iteration. I could not use them for my own purposes. I was thinking about retrieving the information I need using data.keys () ["players"], but I can't handle it at the moment.
for key, value in dct.iteritems(): if value == "players": for key, value in dct.iteritems(): print key, value
Sample of my data:
{ "[CA1]": { "team_tag": "[CA1]", "team_name": "CzechAir", "team_captain": "MatejCzE", "players": { "PeatCZ": "", "MartyJameson": "", "MidnightMaximus": "", "vlak_in": "", "DareD3v1l": "", "Hugozhor78": "" } }, "[GWDYC]": { "team_tag": "[GWDYC]", "team_name": "Guys Who Dated Your Cousin", "team_captain": "Teky1792", "players": { "wondy22": "", "dzavo1221": "", "Oremuss": "", "Straker741": "", "Vasek9266": "" } } }
json python dictionary loops iteration
Aidis
source share