Skip to content Skip to sidebar Skip to footer

Python Iterate Over Multi Value Nested Dictionary

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,51

Solution 1:

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 somethingprint(key_level1, key_level2, val)

Solution 2:

forkey_1inletters_dict:
    forkey_2inletters_dict[key_1]:
        forvalueinletters_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 ...

Post a Comment for "Python Iterate Over Multi Value Nested Dictionary"