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