Python Forum
How to make a list of values from a dictionary list? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to make a list of values from a dictionary list? (/thread-29458.html)



How to make a list of values from a dictionary list? - faryad13 - Sep-03-2020

Hello Guys
Good day

I have a list with dictionaries inside:
L=[{'X': 2593.75}, {'X': 2457.42}, {'X': 2593.75}, {'X': 2457.42}] <class 'list'>

How can I make a new list only with the values. I mean something like:
L_new=[2593.75,2457.42,2593.75,2457.42]

Thank you!


RE: How to make a list of values from a dictionary list? - DeaD_EyE - Sep-03-2020

Iterate over the elements, access the key "X" and append it to a new list.

results = []
for element in L:
    ...
    # this is your task
https://docs.python.org/3/tutorial/datastructures.html#more-on-lists
https://docs.python.org/3/tutorial/datastructures.html#dictionaries

PS: L is a bad name.


RE: How to make a list of values from a dictionary list? - faryad13 - Sep-03-2020

(Sep-03-2020, 02:15 PM)DeaD_EyE Wrote: Iterate over the elements, access the key "X" and append it to a new list.

results = []
for element in L:
    ...
    # this is your task
https://docs.python.org/3/tutorial/datastructures.html#more-on-lists
https://docs.python.org/3/tutorial/datastructures.html#dictionaries

PS: L is a bad name.

Thank you very much for your kind answer!