Editor

Best Score per Player

#561 · Dictionaries and sets · Beginner · Review the AI's code · 35 XP · about 5 min

Someone asked an AI assistant: "Write a function that takes a list of (name, score) results and returns a dictionary with each player's best score." This is its answer. It looks right, but it has a bug.

best_scores(results) should return a dictionary that maps every player who appears in results to the highest score they got, with the players in the order they first appear in the list. Scores are whole numbers, 0 or more.

Examples

best_scores([('ana', 5), ('ben', 3), ('ana', 9)])  # returns {'ana': 9, 'ben': 3}
best_scores([('cy', 7), ('cy', 2)])                # returns {'cy': 7}
best_scores([])                                    # returns {}

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.