extract values from nested dictionaries in a list of tuples

José Angel Bernal

Here is a list of 6 tuples:

listoftuples = [
( { 'd1':[ {'start': 1.2, 'end': 2.7}, {'start': 3.0, 'end': 4.0} ] }, [] ), 
( { 'd2':[ {'start': 1.4, 'end': 2.3}, {'start': 3.2, 'end': 4.3} ] }, [] ), 
( { 'd3':[ {'start': 1.7, 'end': 2.0}, {'start': 3.5, 'end': 4.0} ] }, [] ), 
( { 'd4':[ {'start': 1.5, 'end': 2.4}, {'start': 3.7, 'end': 4.2} ] }, [] ), 
( { 'd5':[ {'start': 1.3, 'end': 2.0}, {'start': 3.0, 'end': 4.0} ] }, [] ), 
( { 'd6':[ {'start': 1.1, 'end': 2.6}, {'start': 3.6, 'end': 4.0} ] }, [] ), 

]

Each tuple contains a dictionary and an empty list. And each dictionary contains a list of 2 dictionaries.

I can´t find the way to loop over all dictionaries and get all the values for the key "start". This would be the result I am looking for:

result_list = [1.2,3.0,1.4,3.2,1.5,3.5,1.3,3.7,1.3,3.0,1.1,3.6]

Any help would be greatly appreciated. Thanks in advance.

Rahul K P

You can do this with list comprehension,

In [1]: [i['start'] for item in listoftuples for i in list(item[0].values())[0]]
Out[1]: [1.2, 3.0, 1.4, 3.2, 1.7, 3.5, 1.5, 3.7, 1.3, 3.0, 1.1, 3.6]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Retrieve values from both nested dictionaries within a list

How to extract duplicate keys and values from a list of python dictionaries?

Fetch specific values from nested tuples in a list

Remove duplicate values from list of nested dictionaries

Extract values from List of Dictionaries using a function

Extract information from a list of dictionaries

How to extract list from list of tuples

Extract values from list and make tuples

Making a list of dictionaries from a list of tuples

Extract item from list of dictionaries using default values

Extract values from list of dictionaries

Extract Values from nested Json list

Extract keys from list of dictionaries

nested dictionary with list of tuples as values from DATA file in python

Extract values from dictionary of dictionaries

Fetching values from dictionaries nested in a list?

Create a smart function to extract values from list of dictionaries

Extract specific dictionaries from a list of nested dictionaries to a temp list

Getting values from a nested list of dictionaries using python

how to extract Values from list of tuples python

Python extract values of a key from a list of lists of dictionaries

Extract Index from a list of dictionaries

How to extract values from defaultdict with nested list values?

parsing a list of dictionaries, nested lists and tuples to produce a new list

Comparing dates from two dictionaries with tuples as values

Extract differences of values of 2 given dictionaries - values are tuples of strings

How to get values from list of nested dictionaries?

Making a nested dictionaries from a list of dictionaries

Python - How to extract values ​from different list of dictionaries in the rows of the dataframe