Python iterate over multi value nested dictionary [closed]

2024/7/7 5:19:55

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?

Answer

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)
https://en.xdnf.cn/q/120740.html

Related Q&A

Why is this python while loop not ending?

I am wondering why this code seems to loop infinitely? The logic, while not False = while True, and this True is referring to 100 < 0 which is false, hence it should execute the print statement ins…

sort a field in ascending order and delete the first and last number [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.This question appears to be off-topic because it lacks sufficient information to diagnose the proble…

PermissionError: [Errno 13] Permission denied:

Im trying to write in a txt file the vertices of a spline mesh, but I get this error: PermissionError: [Errno 13] Permission denied: C\:Windows\system32\vt_84.txtThe code is

python calculator [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable…

How to sequence row based on another row?

I am trying to convert a formula from excel to pandas.The DataFrame looks like this: Column A Column B H H H J J J J K K I want to fill column B to increment while the value in co…

Multiclassification task using keras [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 3…

Clarification needed regarding immutability of strings in Python [closed]

Closed. This question is seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. It does not meet Stack Overflow guidelines. It is not currently accepting …

Please help me in solving Fractional Knapsack problem (Maximum Value of the Loot)

Maximum Value of the LootProblem Introduction: A thief finds much more loot than his bag can fit. Help him to find the most valuable combination of items assuming that any fraction of a loot item can b…

Python countdown clock with GUI [duplicate]

This question already has an answer here:Making a countdown timer with Python and Tkinter?(1 answer)Closed 8 years ago.Im having problems with a countdown clock that I was making in Python for a Raspb…

Confidence calculation in association rule [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, argum…