python字典按照value进行排序

 

d = {'a':1,'b':4,'c':2}
print(sorted(d.items(),key = lambda x:x[1],reverse = True))

 输出

[('b', 4), ('c', 2), ('a', 1)]

 

posted @ 2018-12-31 03:39  anobscureretreat  阅读(191)  评论(0编辑  收藏  举报