How can I sort scores in a leaderboard?

  python, sorting

I’ve been trying to sort a top-5 leaderboard which includes the score and the username of the account that got the score. Here is my current code:

g = open("scores.txt", "r")
score1 = g.readline().strip()
score2 = g.readline().strip()
score3 = g.readline().strip()
score4 = g.readline().strip()
score5 = g.readline().strip()
print(score1,score2,score3,score4,score5)
print(sorted([score1,score2,score3,score4,score5], reverse = True))
g.close()

It seems to work, but it only sorts the leftmost digits of the scores, for example it sorts 100coolguy 50otherguy 10coolguy 2000coolguy 2otherguy as 50otherguy 2otherguy 2000coolguy 10coolguy 100coolguy. Help would be appreciated.

Source: Python Questions

LEAVE A COMMENT