Skip to content Skip to sidebar Skip to footer

Return A List Of Values Of Dictionaries Inside A List

I have a list that contains dictionaries, each of them have the same keys and different values, How can I get a list of values of every dictionary in the list? With dictionary.valu

Solution 1:

Or you can use lambda:

>> b = map(lambda x: x.values(), a)
>> reduce(lambda x, y: x+ y, b)
>> [0, 2, 1, 3, 5, 4, 6, 3, 2]
>> map(lambda x: x['a'], a)
>> [0, 3, 6]

Solution 2:

You use a for loop:

all_values = []
for d in array:
    all_values.extend(d.values())

values_of_a = []
for d in array:
    values_of_a.append(d["a"])

Post a Comment for "Return A List Of Values Of Dictionaries Inside A List"