lambda函数按平均分排序列表
时间: 2023-07-21 21:08:23 浏览: 57
假设有一个包含学生平均分的列表scores,可以按照以下方式使用lambda函数和sorted函数对其进行排序:
```
scores = [{'name': 'Alice', 'average': 85}, {'name': 'Bob', 'average': 72}, {'name': 'Charlie', 'average': 90}]
sorted_scores = sorted(scores, key=lambda x: x['average'], reverse=True)
```
这将按平均分从高到低对学生成绩进行排序,并将结果存储在sorted_scores列表中。可以使用reverse参数来反转排序顺序,以按升序排序。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)