dict - Python determines whether there are duplicate values ​​in a dictionary
扔个三星炸死你
扔个三星炸死你 2017-06-28 09:24:49
0
2
1272

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)?

扔个三星炸死你
扔个三星炸死你

reply all(2)
扔个三星炸死你

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()))
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!