0

For example, if I have a dictionary "dict" that contains 3 lists as values : {1: ['A', 'B', 'C'], 2: ['D'], 3: ['Z']}

How do I check if 'D' is an element inside any of the 3 lists inside the dictionary?

'C' in dict.values() doesn't work, which I think is because "dict" only contains lists as values, rather than letters.

sacuL
  • 49,704
  • 8
  • 81
  • 106
cplusalex
  • 83
  • 4

1 Answers1

2

You could flatten your dictionary values to a single list, and then check if C is in that flat list:

>>> 'C' in [x for i in my_dict.values() for x in i]
True
sacuL
  • 49,704
  • 8
  • 81
  • 106