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
#5
import itertools

x = {
    2:[2, 4, 6, 8],
    3:[3, 6, 9, 12],
    5:[5, 10, 15, 20]
}

values = set(itertools.chain(*x.values()))  # Get set containing all values from dictionary
for i in range(10):
    print(i, i in values)
Output:
0 False 1 False 2 True 3 True 4 True 5 True 6 True 7 False 8 True 9 True
Reply


Messages In This Thread
RE: check if element is in a list in a dictionary value - by deanhystad - May-11-2022, 06:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  element in list detection problem jacksfrustration 5 321 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 403 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  [solved] list content check paul18fr 6 684 Jan-04-2024, 11:32 AM
Last Post: deanhystad
  Dictionary in a list bashage 2 542 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 666 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  Sort a list of dictionaries by the only dictionary key Calab 1 488 Oct-27-2023, 03:03 PM
Last Post: buran
  list in dicitonary element problem jacksfrustration 3 696 Oct-14-2023, 03:37 PM
Last Post: deanhystad
  How to add list to dictionary? Kull_Khan 3 998 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  Find (each) element from a list in a file tester_V 3 1,205 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,833 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