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
  store all variable values into list and insert to sql_summary table mg24 3 84 Today, 09:13 AM
Last Post: Larz60+
Question Keyword to build list from list of objects? pfdjhfuys 3 363 Aug-06-2022, 11:39 PM
Last Post: Pedroski55
  check if element is in a list in a dictionary value ambrozote 4 752 May-11-2022, 06:05 PM
Last Post: deanhystad
  Split a number to list and list sum must be number sunny9495 5 794 Apr-28-2022, 09:32 AM
Last Post: Dexty
  Dictionary from a list failed, help needed leoahum 7 766 Apr-28-2022, 06:59 AM
Last Post: buran
  how to assign items from a list to a dictionary CompleteNewb 3 718 Mar-19-2022, 01:25 AM
Last Post: deanhystad
  AttributeError: 'list' object has no attribute 'values' ilknurg 4 5,790 Jan-19-2022, 08:33 AM
Last Post: menator01
  How to check if a list is in another list finndude 4 878 Jan-17-2022, 05:04 PM
Last Post: bowlofred
  Different out when using conda list and pip list Led_Zeppelin 1 1,349 Jan-14-2022, 09:30 PM
Last Post: snippsat
  Use one list as search key for another list with sublist of list jc4d 4 1,154 Jan-11-2022, 12:10 PM
Last Post: jc4d

Forum Jump:

User Panel Messages

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