字典的排序

from random import randint
dict = {x: randint(60,100) for x in 'xyzabc'}
print dict.items()

print sorted(dict.items(), key=lambda x:x[1],reverse=False)

按dict的第二个元素进行排序

[('b', 64), ('c', 72), ('z', 90), ('y', 97), ('x', 97), ('a', 100)]
原文地址:https://www.cnblogs.com/lirunzhou/p/7325573.html