I am trying to write a script finding duplicated values in a dictionary. My dictionary is having an integer key and a list as a value:
{5: ['13139', '3219', '3'], 6: ['14072', '3214', '3'], 7: ['13137', '3219', '3'], 8: ['13141', '3219', '3'], 9: ['13139', '3219', '3']}
Here is my code:
for key, value in dict.iteritems():
for other_key, other_value in dict.iteritems():
if value == other_value and key != other_key:
print "We have duplicated values at key {} and key {}".format(key, other_key)
The problem is that when I run the script I got duplicated lines like this:
We have duplicated values at key 5 and key 9
We have duplicated values at key 9 and key 5
So I want to omit the second row and this script also won't show me if I have duplicated values on more than 2 keys for example if I have duplicated values at key 5, 9 and 52 it will show me:
We have duplicated values at key 5 and key 9
We have duplicated values at key 5 and key 52
We have duplicated values at key 9 and key 5
We have duplicated values at key 9 and key 52
And I want to show me that I have duplicated values at key 5, 9 and 52
I also want to show me all the keys with duplicated values so for example I can have duplication at key 5, 9 and 52 and another duplication of the values at key 40 and 65.