我有從閱讀txt文件中創建的2D列表。我寫了這個代碼進行排序最高值的列表 - 位置5在2D列表上排序
sort = list(sorted(sort,key=lambda x: x[5],reverse=True))
for i in range(0, len(sort)):
print("Name:",sort[i][0],"\tscore1:",sort[i][1],"\tscore2:",sort[i][2],"\tscore3:",sort[i][3], "\tHighest:",sort[i][5])
代碼似乎從,除了工作,由於某種原因,它把的10(只有2位數字在列表的底部。而不是在頂部我有使用最大函數達到最高數,然後簡單地將其附加到每個列表的末尾
名:乙score1:6 score2:1 score3:3最高:6
名稱:Z得分1:4得分2:4得分3:5最高:5
名稱:尼爾score1:4 score2:1 score3:3最高:4
名稱:fred的score1:10 score2:0 score3:0最高:10
任何幫助理解。
你能顯示你的輸入列表嗎? – 2014-11-24 23:15:48