Pygame的高分不会

2024-10-02 18:16:45 发布

您现在位置:Python中文网/ 问答频道 /正文

大家好,请帮助我,这是一个功能,排序的球员,他们的高分。但这不是分类

def sortByScore(inputPlayerScore):
    return inputPlayerScore[1]


def highscore():


    try:
       scores = open("scores.txt", "r")
       highScores = list()   # place all your processed lines in here
       for line in scores.readlines():
           lineParts = line.split(": ")
           if len(lineParts) > 1:
               lineParts[-1] = lineParts[-1].replace("\n", "")
               highScores.append(lineParts)   # sorting uses lists
       print(sorted(highScores, key=sortByScore, reverse = True))   # get this out of for loop
    except Exception:
        pass

输入文件是:

jkh: 32
daasd: 6
dasdf: 9
wfsdwf: 125
dada: 5
jkh: 62

Tags: in功能for排序defline分类球员