I'm fairly new to python. I've made a hangman-style game that asks users for a name and password and records their score. It then adds these to a file (highscoresUNSORTED.txt). I tried to add all the lines to a list (xList), sort the list and add that back to another file called highscoresSORTED.txt . My code doesn't seem to add anything to the list for some reason, can anyone suggest why?
xList = []
f = open("highscoresUNSORTED.txt", "a+")
f.write("\n" + str(score) + "," + username + "," + password)
for line in f:
xList.append(line)
print(xList)
f.close()
xList.sort()
print(xList)
fout = open("highscoresSORTED.txt", "w")
for i in xList:
fout.write(xList[i] + "\n")
fout.close()