Sorting dictionary keys in python
This question already has an answer here:
>>> mydict = {'a':1,'b':3,'c':2}
>>> sorted(mydict, key=lambda key: mydict[key])
['a', 'c', 'b']
我喜欢这一个:
sorted(d, key=d.get)
my_list = sorted(dict.items(), key=lambda x: x[1])
链接地址: http://www.djcxy.com/p/18146.html
下一篇: 在Python中对字典键进行排序