我对 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
