-7

I have the below data structure call letters_dict:

'aa': {'Price': '147,130,104,24,19',
       'Qty': '262,53,65,80,185,210',
       'Time': '51302324915,51308461317,51316258845,51324326568'},

'bb': {'Price': '196,203,209,177,150,160,160,180,194',
       'Qty': '129,268,225,228,176,76,17,45,207,61,143,195,230,97',
       'Time': '51305086913,51314981179,51323072726,51435766657,51597990966'}}

I want to iterate over each item of the outer dictionary and then the inner values, price qty and time and then each value within price qty and time to then do data processing. What is the best way to do this?

Jaron787
  • 562
  • 1
  • 11
  • 29

2 Answers2

0

First iterating over the outer values using key_level1 and val_level1, then iterating over inner values using key_level2, val_level2:

for key_level1, val_level1 in r.items():
        for key_level2, val_level2 in val_level1.items():
            for val in val_level2.split(','):
                # Example:
                # do something
                print(key_level1, key_level2, val)
nikpod
  • 1,238
  • 14
  • 22
0
for key_1 in letters_dict:
    for key_2 in letters_dict[key_1]:
        for value in letters_dict[key_1][key_2].split(','):

This is to me the simplest way (doesn't mean the best). I'm not sure why you didn't even try it ...

Marc Z
  • 116
  • 5