Python Forum
Get New List Based on Dictionary Key
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get New List Based on Dictionary Key
#1
I'm new to Python. If I have a list indicate the order for a new list with the key in a dictionary, how could I get the new list with the values in the dictionary.

For instance:

l = ['a','b','a','c','b']
D = {'a':[3,2],'b':[4,5],'c':[1]}

How can I get a new list as:
L = [3,4,2,1,5]


A lot of thanks!
Reply


Messages In This Thread
Get New List Based on Dictionary Key - by leoahum - Oct-02-2018, 10:15 PM
RE: Get New List Based on Dictionary Key - by buran - Oct-03-2018, 02:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a list of dictionaries by the only dictionary key Calab 2 568 Apr-29-2024, 04:38 PM
Last Post: Calab
  unable to remove all elements from list based on a condition sg_python 3 477 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Dictionary in a list bashage 2 581 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 726 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  How to add list to dictionary? Kull_Khan 3 1,031 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  check if element is in a list in a dictionary value ambrozote 4 2,006 May-11-2022, 06:05 PM
Last Post: deanhystad
  Dictionary from a list failed, help needed leoahum 7 2,027 Apr-28-2022, 06:59 AM
Last Post: buran
  select Eof extension files based on text list of filenames with if condition RolanRoll 1 1,539 Apr-04-2022, 09:29 PM
Last Post: Larz60+
  how to assign items from a list to a dictionary CompleteNewb 3 1,608 Mar-19-2022, 01:25 AM
Last Post: deanhystad
  Python, how to manage multiple data in list or dictionary with calculations and FIFO Mikeardy 8 2,659 Dec-31-2021, 07:47 AM
Last Post: Mikeardy

Forum Jump:

User Panel Messages

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