Python Forum

Full Version: How to make a list of values from a dictionary list?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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!
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/datas...e-on-lists
https://docs.python.org/3/tutorial/datas...ctionaries

PS: L is a bad name.
(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/datas...e-on-lists
https://docs.python.org/3/tutorial/datas...ctionaries

PS: L is a bad name.

Thank you very much for your kind answer!