gpt4 book ai didi

python - 如何使元组顺序相反?

转载 作者:太空宇宙 更新时间:2023-11-04 05:40:29 24 4
gpt4 key购买 nike

我对 python 比较陌生,所以我需要一些帮助来为字典设置从高到低的排序系统。我使用:

highestList = sorted(classFile.items(), key=lamda x: x[::-1])

这将我的字典排序为一个元组,但这是错误的方法。它输出:

[('Dylan', 4), ('Jimmy', 5), ('Mark', 5), ('Chris', 7)]

我希望它输出的地方:

[('Chris', 7), ('Mark', 5), ('Jimmy',5), ('Dylan',4)]

最佳答案

highestList = sorted(classFile.items(), key=lamda x: x[::-1],reverse=True)

使用reverse=True

关于python - 如何使元组顺序相反?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34117274/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com