I have changed a text file's contents, named 'HighScores.txt', into a list and sorted it using this code:
scores = []
with open("HighScores.txt") as f:
for line in f:
name, score = line.split(',')
score = int(score)
scores.append((name, score))
scores.sort(key=lambda s: s[1])
The text file looks like this:
hank, 11
jayda, 15
chris, 12
How can I turn this list back into string so I can write it back into a txt file?
First Implementation of a fix was:
f = open("HighScores.txt", 'r+')
for t in ((name, score)):
f.write(' '.join(str(s) for s in t) + '\n')
Error:
File "C:\Users\samiv\Desktop\Computer Science-20190310T115417Z-001\Computer Science\Coding Project - Copy.py", line 102, in game
f.write(' '.join(str(s) for s in t) + '\n')
TypeError: 'int' object is not iterable