相关疑难解决方法(0)

python字典中的5个最大值

我有一个这样的字典:

A = {'a':10, 'b':843, 'c': 39,.....}
Run Code Online (Sandbox Code Playgroud)

我想得到这个dict的5个最大值,并用这个存储一个新的dict.为了获得我做的最大值:

max(A.iteritems(), key=operator.itemgetter(1))[0:]
Run Code Online (Sandbox Code Playgroud)

也许这是一件容易的事,但我长期坚持下去.请帮忙!!!

python dictionary max

52
推荐指数
4
解决办法
7万
查看次数

字典中的最高值

如何从字典中查找前3个列表?

>>> d
{'a': 2, 'and': 23, 'this': 14, 'only.': 21, 'is': 2, 'work': 2, 'will': 2, 'as': 2, 'test': 4}
Run Code Online (Sandbox Code Playgroud)

预期结果:

and: 23
only: 21
this: 14
Run Code Online (Sandbox Code Playgroud)

python dictionary

28
推荐指数
2
解决办法
4万
查看次数

标签 统计

dictionary ×2

python ×2

max ×1