对字典进行排序


sorted(字典名.items(), key=lambda x: x[1])

 

x = a[a['列名'] == 值]['列名']
y = a[a['列名'] == 值]['列名']

dic_xy = dict(zip(x,y))
lst_xy = sorted(dic_xy.items(), key=lambda x: x[1],reverse = True)
print(lst_xy)
dic = {}
for index in range(10):
    dic[lst_xy[index][0]] = lst_xy[index][1]
print(dic)

 


2020-06-09

 

 
原文地址:https://www.cnblogs.com/hany-postq473111315/p/13080091.html