整理一下key排序和value排序
- key
tmpdict = {"1":20,"2":50,"3":40,"4":100,"5":80}
# key从大到小
>>> for i in sorted(tmpdict.keys(),reverse=True):
... print([i,tmpdict[i]])
...
['5', 80]
['4', 100]
['3', 40]
['2', 50]
['1', 20]
- value
>>> tmpdict = {"1":20,"2":50,"3":40,"4":100,"5":80}
# value从大到小
>>> orderdict = sorted(tmpdict.items(),key=lambda item:item[1],reverse=True)
>>> orderdict
[('4', 100), ('5', 80), ('2', 50), ('3', 40), ('1', 20)]