scores = []
with open("scores.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])
for name, score in scores:
print(name + ", " + str(score))
This code can be used to show a txt file looking like this (disordered):
alpha, 3
beta, 1
gamma, 2
To looking like this:
beta, 1
gamma, 2
alpha, 3
How can I modify the code so that it instead prints as:
alpha, 3
gamma, 2
beta, 1