首先定义一个保存学生成绩的列表。将每名学生的信息都保存在一个字典中,然后根据学生的总成绩进行排序。
代码实现:
student_grade = [90, 95, 80, 75, 60, 99, 100, 55, 78]
student_name = ['张三', '李四', '李华', '小张', '小华', '小虎', '小军', '小花', '小明']
grade_list = list(zip(student_name, student_grade))
grade_list.sort(reverse=True, key=lambda x:x[1]) # //降序输出
grade_dictionary = dict(grade_list)
print(grade_dictionary)
注意事项:进行排序的时候要先将其转换为列表来排序,最后转换为字典输出。
运行结果: