The input is a dictionary, for example: {'A': 1, 'B': 1, 'C': 3}
, how to determine whether there are duplicate values in the dictionary
(values
)?
扔个三星炸死你2017-06-28 09:26:49
Reference article: Python’s list, dict, json and other common operations
Check whether there are duplicate values in the dictionary
>>> def has_duplicates(d):
return len(d) != len(set(d.values()))
>>> print has_duplicates({'A': 1, 'B': 1, 'C': 3})
True
>>>
阿神2017-06-28 09:26:49
d = {'A': 1, 'B': 1, 'C': 3}
#不相等即有重复值
print len(d.values()) == len(set(d.values()))