【发布时间】:2016-04-01 18:35:05
【问题描述】:
with open('classroom1.csv') as csvfile:
readCSV = csv.reader(csvfile)
for row in readCSV:
name = row[0]
scores = [int(c) for c in row[1:]]
total = sum(scores)
到目前为止,这是我的代码,我想按升序对其进行排序。我知道reverse=True 会帮助我,但我不知道如何在这里使用它。
我试过了:
srt = sorted(total, key=lambda x : x[1], reverse=True)
print(name,srt)
但它不起作用。
我的列表是[userName, score1, score2, score3],例如[James, 5, 8, 4]
【问题讨论】:
-
如果我们知道您的列表是什么样的以及应该是什么样的,那将会很有帮助。
-
所以你想要
['James',5,4,8]-->['James',4,5,8]? -
@Stidgeon 按总分排序。
-
如果没有MCVE,这是没有希望的
-
请不要破坏您的问题。如果您想删除您的问题,请标记以引起版主注意。