相关疑难解决方法(0)

python排序函数中的关键参数如何工作?

说我有

votes = {'Charlie': 20, 'Able': 10, 'Baker': 20, 'Dog': 15}
Run Code Online (Sandbox Code Playgroud)

我明白

print(sorted(votes.items(), key = lambda x: x[1]))
Run Code Online (Sandbox Code Playgroud)

会导致

[('Able',10),('Dog',15),('Baker',20),('Charlie',20)]`

但这是如何工作的?

python sorting dictionary

8
推荐指数
3
解决办法
4309
查看次数

标签 统计

dictionary ×1

python ×1

sorting ×1