'Check if value inside the list in dictionary values [duplicate]

Lets say I have a dictionary:

dict = {'A': ['one', 'two'], 'B': [3, 4, 5, 5, 6, 7, 8, 9, 10], 'C': [11, 12]}

I want to check if some value is in the dictionary. This is what I try and what I get:

>>>value = 'one'
>>>value in dict.values()
False

I assume this is because my value is in list. How do I check simply if the value is in any list of values then?



Solution 1:[1]

I don't think there's a "simple" way. You should iterate over each list and perform a check:

any(value in val for val in dict.values())

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ForceBru