nested

Pandas: Explode a list of nested dictionaries column and append as new rows

Pandas: Explode a list of nested dictionaries column and append as new rows Question: Please consider the below dict for example: d2 = [{‘event_id’: ‘t1’, ‘display_name’: ‘t1’, ‘form_count’: 0, ‘repetition_id’: None, ‘children’: [{‘event_id’: ‘t_01’, ‘display_name’: ‘t(1)’, ‘form_count’: 1, ‘repetition_id’: ‘t1’, ‘children’: [], ‘forms’: [{‘form_id’: ‘f1’, ‘form_repetition_id’: ‘1’, ‘form_name’: ‘fff1’, ‘is_active’: True, ‘is_submitted’: False}]}], ‘forms’: []}, …

Total answers: 1

Trying to use nested for loop to correctly parse nested list items

Trying to use nested for loop to correctly parse nested list items Question: I have a nested list (derived from a psycopg2 psql query) that contains a list of company names, stock tickers, and industries. I am using a subsequent nested for loop to try and extract the 1st (company name) and 3rd (industry) elements …

Total answers: 1

Function to dynamically extract values from multiple nested dictionary in Python

Function to dynamically extract values from multiple nested dictionary in Python Question: The problem statement is to write a function which will take a input dictionary object and return a list of all the values, even in case of multi-level nested dictionaries inside the input dictionary object. Example of such a nested dictionary below: { …

Total answers: 3

How to group the same values into same key?

How to group the same values into same key? Question: I have an assignment to do this things without import any helpful function, could you guys help me? Thanks! data = [ [‘num’,’e1′,’e2′,’e3′], [‘2002′,’p’,’r’,’i’], [‘2002′,’k’,’r’,’i’], [‘2001′,’k’,’r’,’e’], [‘2004′,’p’,’a’,’p’], [‘2004′,’p’,’s’,’f’] ] newlist = [ {‘num’: ‘2001’, ‘e1’: ‘k’, ‘e2’: ‘r’, ‘e3’: ‘e’}, {‘num’: ‘2002’, ‘e1’: ‘p’, ‘e2’: …

Total answers: 1

Making list from elements from each level of a nested list

Making list from elements from each level of a nested list Question: I have a list: cleaner = [[‘Re:’, ’31_300323′, ‘RE777′]] I want to check if another list contains same value, I write: any(’31_300323’ in sl for sl in cleaner) , and get "True", but if I write: suka = [] for h in cleaner: …

Total answers: 2

Python for loop through nested dictionary question?

Python for loop through nested dictionary question? Question: Trying to loop through a nested dictionary and want to store values into name, age and occupation. Without manually creating those variables within the for loop. Is this even possible? Just trying to create cleaner looking code. Thank you. people = { 1: {"name": "Simon", "age": 20, …

Total answers: 3

Using a list to find occurrences in a nested dictionary

Using a list to find occurrences in a nested dictionary Question: So I have a nested dictionary: {1: {‘letter’: ‘A’, ‘is_vowel’: True, ‘point_value’: 1}, 2: {‘letter’: ‘B’, ‘is_vowel’: False, ‘point_value’: 3}, 3: {‘letter’: ‘C’, ‘is_vowel’: False, ‘point_value’: 3}, 4: {‘letter’: ‘D’, ‘is_vowel’: False, ‘point_value’: 2}, 5: {‘letter’: ‘E’, ‘is_vowel’: True, ‘point_value’: 1}, 6: {‘letter’: ‘F’, …

Total answers: 5

Nested dictionary for loop with def (INDENTENTION PROBLEM)

Nested dictionary for loop with def (INDENTENTION PROBLEM) Question: I am learning Python with the 2°Ed. Automate the boring stuff with python, and I came across with a indentention problem. Can someone explain what I am doing wrong? I am trying to add a indentention after the for loop to insert the num_brought value, but …

Total answers: 1

Python: return nested dict of values

Python: return nested dict of values Question: I’m typing 3 list of loops, and I need return dict like in docstring. And it’s wrong. How can I solve problem? For each period you have to count incomes and expenses and total occurrence. Changes out of functions body are not allowed. Additional imports are not allowed. …

Total answers: 2