小编M. *_*lam的帖子

列表按字母顺序而不是数字顺序排列

我已经累积了一个分数列表,其中包含在列表中获得该特定分数的人的用户名。

然后我使用以下代码按降序对分数进行排序。

winnerScore.sort()
winnerScore.reverse()
Run Code Online (Sandbox Code Playgroud)

以下是打印列表 'winnerScore' 时的结果。

['j 78', 'j 36', 'i 90', 'i 58']
Run Code Online (Sandbox Code Playgroud)

该函数根据用户名而不是实际代码对它们进行了排序。

负责对列表进行排序的函数如下:

global winnerScore
with open("diceRoll.txt","r") as x_file:
    contents = x_file.readlines()

oneScore = contents[count-1]
oneScore = oneScore.split(" ")
print(oneScore)
n = oneScore[-2][-1] + " " + oneScore[-1]

winnerScore.append(n)

if len(oneScore) != 0:
    winnerScore.sort()
    winnerScore.reverse()
Run Code Online (Sandbox Code Playgroud)

我已经从文本文件中读取了分数和用户名。

我可以更改哪些内容以确保根据用户名的实际分数对“winnerScore”列表进行排序?

python arrays list

5
推荐指数
1
解决办法
98
查看次数

标签 统计

arrays ×1

list ×1

python ×1