Kodewick
Start learning →
Mini challenge←0 / 80

Arcade high scores

#080Mini challengeDictsSorting8 min

The arcade logs each game on a line: a name and a score. People play several games, but only their best counts. Write top_players(text) to return the names with the top 3 best scores, highest first; with fewer than 3 players, return them all. No two best scores are the same.

Examples
top_players("Kai 50\nJo 80\nKai 90\nLe 20")→['Kai', 'Jo', 'Le']
top_players("")→[]
main.py
def top_players(text):
    best = {}
    for line in text.splitlines():
        name, score = line.split()
        score = int(score)
        # your code here: if this game beats their saved score (or they have none yet), save it
    # your code here: sort the names by best score, highest first, and return the top 3
    return []
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.