84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
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