的主要目的
collections.OrderedDict是保留元素 插入 的顺序。
您想要的是
collections.Counter,它内置了n个最常用的功能:
>>> dictionary={'a':10,'b':20,'c':30,'d':5}>>> import collections>>> collections.Counter(dictionary).most_common(2)[('c', 30), ('b', 20)]
的主要目的
collections.OrderedDict是保留元素 插入 的顺序。
collections.Counter,它内置了n个最常用的功能:
>>> dictionary={'a':10,'b':20,'c':30,'d':5}>>> import collections>>> collections.Counter(dictionary).most_common(2)[('c', 30), ('b', 20)]