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.
My code examples are always for Python >=3.6.0
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
  Class-Aggregation and creating a list/dictionary IoannisDem 1 173 Oct-03-2021, 05:16 PM
Last Post: Yoriz
  How to pass list of values to a API request URL chetansaip99 0 473 Sep-28-2021, 07:37 AM
Last Post: chetansaip99
  Why changing data in a copied list changes the original list? plumberpy 3 478 Aug-14-2021, 02:26 AM
Last Post: plumberpy
  Make Groups with the List Elements quest 2 484 Jul-11-2021, 09:58 AM
Last Post: perfringo
  Compile list of dictianories out of another list of dictianories by certain keys CatorCanulis 10 1,082 Jun-10-2021, 08:35 PM
Last Post: perfringo
  Getting values from a dictionary brunolelli 5 1,071 Mar-31-2021, 11:57 PM
Last Post: snippsat
  Python dictionary with values as list to CSV Sritej26 4 914 Mar-27-2021, 05:53 PM
Last Post: Sritej26
  Order a list with successive permutations based on another list yvrob 3 863 Mar-19-2021, 08:20 AM
Last Post: supuflounder
  Conceptualizing modulus. How to compare & communicate with values in a Dictionary Kaanyrvhok 7 1,223 Mar-15-2021, 05:43 PM
Last Post: Kaanyrvhok
  Saving list in a list quest_ 3 1,016 Mar-10-2021, 09:58 AM
Last Post: quest_

Forum Jump:

User Panel Messages

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