I have managed to write the scores and names of anybody who wins a simple dice game I created to an external text document. How would I sort the top scores from this document and display them on the console alongside the name that achieved that score?
Code used to write score and name to the text document:
winners = open("winners.txt", "a")
winners.write(p1_username) #writes the name
winners.write("\n")
winners.write(str(p1_total)) #writes the score
Tried entering the data into an array of tuples and sorting them according to the numerical value in each tuple when I found this, so tried
count = len(open("winners.txt").readlines( ))
winners_lst = [(None, None)] * count
f = open("winners.txt", "r")
lines2 = f.readlines()
winners_lst[0][0] = lines2[0]
winners_lst[0][0] = lines2[1]
but that returns
TypeError: 'tuple' object does not support item assignment
Edit: I am not asking why my solution didn't work, I am asking what I could do to make it work or for an alternate soloution.