FunctionRacerProblemsRace

Winner of Each Group

HardpandasPython

players has columns id and grp. matches has first, second, first_score and second_score: two player ids and the points each made in that match.

A player's total is all the points they made, in either seat. Return a dict from each group to the id of its player with the highest total. If totals tie, the lowest id wins. A player with no matches has a total of 0.

Example 1

players {"id":[1,2,3,4,5],"grp":["A","A","B","B","B"]}
matches {"first":[1,3,2,4],"second":[2,4,1,5],"first_score":[3,1,2,0],"second_score":[0,4,2,4]}
returns {"A":1,"B":4}

Totals: player 1 has 3 + 2 = 5, player 2 has 0 + 2 = 2, player 3 has 1, player 4 has 4 + 0 = 4, player 5 has 4. In B, players 4 and 5 tie and the lower id wins.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More pandas problems