python基础(如何根据字典中值的大小,对字典的项进行排序)
作者:互联网
案例:
某班英语成绩以字典形式存储为:{'LiLei':79, 'jim':88,'Lucy':92...},根据学生成绩高低,计算排名
方法一:
from random import randint
d = {x: randint(60,100) for x in 'abcxyz'}
print(sorted(d.items(),key=lambda x:x[1]))
方法二:
print(sorted(zip(d.values(),d.keys())))
标签:randint,python,某班,sorted,print,中值,成绩,字典 来源: https://blog.csdn.net/jamfiy/article/details/87971914