Skip to content
Advertisement

Python – Check if value is unique in dictionary of lists

Is there a way to check if a value is unique for a specific list, within a dictionary of lists? If yes, I would like to know in which key/list pair/s the value is present.

For example: {1: [3, 4, 5], 2: [4], 3: [5], 6: [3, 5, 9], 8: [3 ,8]}

I want to check if 3 is present in any of the other lists within the dictionary, besides 1: [3, 4, 5(compare it with all others). Since it is, then I must receive as a result 6 and 8, because these are the keys, which corresponding lists have this value.

Advertisement

Answer

Try this:

JavaScript

Reuslt:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement