简体   繁体   中英

Python: Extracting data from nested dictionary with single keys

I have a list of about 300 dictionary each of which has elements as follows:

myDictList[0]
{1: {1: {'XX':5, 'YY':7}}}

myDictList[1]
{11: {25: {'XX':15, 'YY':73}}}

I want to instead generate

myDictList[0] = {}
myDictList[1] = {}
myDictList[0][1][1] = {'XX':5, 'YY':7}
myDictList[1][11][25] = {'XX':15, 'YY':73}

I am trying a for loop right now. Is there a pythonic way to do this?

Edit:

myDictList is list and others are dictionary as follows:

myDictList[0] = {}
myDictList[0][1] = {}
myDictList[0][1][1] = {}

There is nothing to do:

myDictList[0] == {1: {1: {'XX':5, 'YY':7}}}

Is the same as:

myDictList[0][1][1] == {'XX':5, 'YY':7}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM