计算字典中值的频率

use*_*567 4 python dictionary

我的字典包含这样的值{a:3,b:9,c:88,d:3}我想计算特定数字出现在上面字典中的次数.例如上面的字典3在字典中出现两次请帮助编写python脚本

phi*_*hag 12

你应该使用collections.Counter:

>>> from collections import Counter
>>> d = {'a':3, 'b':9, 'c':88, 'd': 3}
>>> Counter(d.values()).most_common()
[(3, 2), (88, 1), (9, 1)]
Run Code Online (Sandbox Code Playgroud)