Python Forum
check if element is in a list in a dictionary value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
check if element is in a list in a dictionary value
#1
how can I check if an element is in a list in a dictionary value? for instance

how can I get this code to output "Found it"

a = "Doors"

dict = {"a":["Doors","Windows"],"b":"Stairs"}

if a in dict.values():
print("Found it")
else:
print("sorry")

Thank you
Reply


Messages In This Thread
check if element is in a list in a dictionary value - by ambrozote - May-11-2022, 04:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a list of dictionaries by the only dictionary key Calab 2 686 Apr-29-2024, 04:38 PM
Last Post: Calab
  element in list detection problem jacksfrustration 5 528 Apr-11-2024, 05:44 PM
Last Post: deanhystad
  Help with to check an Input list data with a data read from an external source sacharyya 3 518 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  [solved] list content check paul18fr 6 827 Jan-04-2024, 11:32 AM
Last Post: deanhystad
  Dictionary in a list bashage 2 625 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 780 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  list in dicitonary element problem jacksfrustration 3 794 Oct-14-2023, 03:37 PM
Last Post: deanhystad
  How to add list to dictionary? Kull_Khan 3 1,072 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  Find (each) element from a list in a file tester_V 3 1,286 Nov-15-2022, 08:40 PM
Last Post: tester_V
  Сheck if an element from a list is in another list that contains a namedtuple elnk 8 1,939 Oct-26-2022, 04:03 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