#592 · Dictionaries and sets · Intermediate · Find and fix · 65 XP · about 9 min
A basketball league records each game a player scores in as a (player, points) pair. top_scorer(games) should add up each player's points over all their games and return the name of the player with the highest total. If two or more players share the highest total, return the name that comes first in alphabetical order. With no games at all, return None.
The code in the editor has two bugs. A player who scores in several games is credited with only their last game: for [('ana', 5), ('ben', 7), ('ana', 4)] it returns 'ben', though Ana scored 9. And when two players finish level, it does not always pick the name that comes first alphabetically.
top_scorer([('ana', 10), ('ben', 7)]) # returns 'ana' top_scorer([('ana', 5), ('ben', 7), ('ana', 4)]) # returns 'ana' top_scorer([('zed', 6), ('amy', 6)]) # returns 'amy' top_scorer([]) # returns None
games has 0 to 10,000 pairs.First solves only, ranked by stars and then time.