如何使元组的顺序相反

  • 本文关键字:顺序 何使 元组 python
  • 更新时间 :
  • 英文 :


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

最新更新