排序值并返回来自dict python的键的列表

可能重复:
Python:按值排序字典

我有这样一本字典:

A = {'Name1':34, 'Name2': 12, 'Name6': 46,....}

我想要一个按值排序的键列表,例如[Name2, Name1, Name6....]

谢谢!!!


使用以get方法作为关键字的sorted (可以通过迭代访问字典关键字):

sorted(A, key=A.get)

使用sortedkey参数

sorted(d, key=d.get)

sorted(a.keys(), key=a.get)

这对键进行排序,并且对于每个键,都使用a.get来查找要用作排序值的值。

链接地址: http://www.djcxy.com/p/18147.html

上一篇: sort values and return list of keys from dict python

下一篇: Sorting dictionary keys in python