字典的排序

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)]
posted @ 2017-08-09 15:28  赭山东路  阅读(153)  评论(0编辑  收藏  举报