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)?
{'A': 1, 'B': 1, 'C': 3}
duplicate values in the dictionary
values
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 >>>
d = {'A': 1, 'B': 1, 'C': 3} #不相等即有重复值 print len(d.values()) == len(set(d.values()))
Reference article: Python’s list, dict, json and other common operations
Check whether there are duplicate values in the dictionary