I'm creating a game and I'd like to print out the user scores from highest to lowest.
This is my code so far
player_scores = {}
for line in reversed(open("playerscores.txt").readlines()):
    name, score = line.rstrip('\n').split(' / ')
    score = int(score)
    if name in player_scores and len(player_scores[name]) < 3:
        player_scores[name].append(score)
    if name not in user_scores:
        player_scores[name] = list((score,))
Names in playerscores.txt are stored like:
Bob / 10
Jill / 10
My code takes the last 3 scores from the user(last 3 lives) and uses that as the base. I need print the users names along with the highest scores to the lowest.
The solutions at Sort a Python dictionary by value do not work. I end up getting outputs such as:
[('Alex', [1]), ('Joeseph', [32, 576]), ('Steve', [33]), ('Bob', [55, 22])]
which are not sorted.
 
     
     
     
    