Python Forum
How to make a list of values from a dictionary list?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make a list of values from a dictionary list?
#1
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!
Reply
#2
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
(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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I'm assuming you're asking about accessing nested dictionary keys and values in Pytho DavidSah 0 580 Dec-18-2025, 01:54 AM
Last Post: DavidSah
Question [SOLVED] Access keys and values from nested dictionary? Winfried 4 914 Nov-17-2025, 11:47 AM
Last Post: Winfried
  Replace values in Yaml file with value in dictionary PelleH 1 3,817 Feb-11-2025, 09:51 AM
Last Post: alexjordan
  Make a list learningpythonherenow 1 1,352 Oct-11-2024, 11:49 AM
Last Post: Pedroski55
  Assigning cycle values in a list nmancini 3 2,061 Sep-16-2024, 09:35 PM
Last Post: deanhystad
  remove duplicates from dicts with list values wardancer84 27 10,966 May-27-2024, 04:54 PM
Last Post: wardancer84
  Strange behavior list of list mmhmjanssen 3 2,334 May-09-2024, 11:32 AM
Last Post: mmhmjanssen
  Sort a list of dictionaries by the only dictionary key Calab 2 2,287 Apr-29-2024, 04:38 PM
Last Post: Calab
Question Using Lists as Dictionary Values bfallert 8 3,938 Apr-21-2024, 06:55 AM
Last Post: Pedroski55
  Dictionary in a list bashage 2 2,254 Dec-27-2023, 04:04 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020