按照value值进行排序
方式1
d = {
"k1":2,"k2":1,"k3":5,"k4":4}
#按照value,从大到小排序
r = sorted(d.items(),key=lambda x:x[1],reverse=True)
print(r)
#--> [("k3",5),("k4",4),("k1",2),("k2",1)]
方式2
d = {
"k1":2,"k2":1,"k3":5,"k4":4}
#按照value,从大到小排序
r = sorted(d,key=d.get,reverse=True)
print(r)
#--> ["k3","k4","k1","k2"]