Я делаю систему рекордов для своего кода для курсовой работы, мне удалось отсюда с некоторой помощью отсортировать мои номера, но теперь я решил добавить имена, чтобы высокие баллы соотносились с человеком, это действительно сортирует его пока это мой код:
player1=input("input")
player1score=int(input("input"))
highscore = open("Scores.txt", "r")
whowon=("{0}-{1}".format(player1score,player1))
highscores = highscore.readlines()
highscore.close()
highscore = open("Scores.txt", "a")
highscore.write(whowon)
highscore.write("\n")
highscore.close()
highscore = open("Scores.txt", "r")
highscores = highscore.readlines()
highscores = [ x.rstrip() for x in highscores ]
highscores.sort(reverse=True, key=int)
top1=highscores[0]
top2=highscores[1]
top3=highscores[2]
top4=highscores[3]
top5=highscores[4]
top=("{0}\n{1}\n{2}\n{3}\n{4}\n".format(top1, top2, top3, top4, top5))
highscore.close()
highscore=open("Scores.txt", "w")
highscore.write(top)
highscore.close()
файл выводит
68-Dylan
45-Snones
70-Pedro
Есть ли способ разделить целочисленные значения, отсортировать их, а затем соединить их вместе соответственно? Код ошибки, который я получаю для этого:
highscores.sort(reverse=True, key=int)
ValueError: invalid literal for int() with base 10: '68-Dylan'