【发布时间】:2013-03-28 23:03:51
【问题描述】:
可以这样访问计数器的最大值:
c = Counter()
c['foo'] = 124123
c['bar'] = 43
c['foofro'] =5676
c['barbar'] = 234
# This only prints the max key
print max(c), src_sense[max(c)]
# print the max key of the value
x = max(src_sense.iteritems(), key=operator.itemgetter(1))[0]
print x, src_sense[x]
如果我想要一个按降序计数的排序计数器怎么办?
如何访问第 2 个最大值、第 3 个或第 N 个最大值键?
【问题讨论】:
标签: python collections dictionary counter multiset