Python Forum
access dictionary with keys from another and write values to list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
access dictionary with keys from another and write values to list
#6
>>> dict1 = {'red':3,'blue':4,'yellow':6}                                                                                             
>>> dict2 = {'red': 'is a color', 'blue': 'is another color'}     
>>> [v for k, v in dict2.items() if k in set(dict1).intersection(dict2)]
['is a color', 'is another color'] 
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: access dictionary with keys from another and write values to list - by perfringo - Jun-03-2020, 04:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Using Lists as Dictionary Values bfallert 8 354 Apr-21-2024, 06:55 AM
Last Post: Pedroski55
  Dictionary in a list bashage 2 569 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  How to access values returned from inquirer cspower 6 831 Dec-26-2023, 09:34 PM
Last Post: cspower
  filtering a list of dictionary as per given criteria jss 5 700 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  need to compare 2 values in a nested dictionary jss 2 880 Nov-30-2023, 03:17 PM
Last Post: Pedroski55
  Copying the order of another list with identical values gohanhango 7 1,171 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,266 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Sort a list of dictionaries by the only dictionary key Calab 1 504 Oct-27-2023, 03:03 PM
Last Post: buran
  Access list of dictionaries britesc 4 1,091 Jul-26-2023, 05:00 AM
Last Post: Pedroski55
  Comparing List values to get indexes Edward_ 7 1,186 Jun-09-2023, 04:57 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