Build the league table with tiebreakers
A neighbourhood football league in Buenos Aires has finished its season and the organisers need the final table. Teams are ranked by points (higher first). Teams level on points are ordered by goal difference (goals for minus goals against, higher first), then by goals for (higher first), and finally by team name in ordinary alphabetical order (A before B, as Python compares strings).
Task: the first line holds n (1 to 40). Each of the next n lines has name points goals_for goals_against (the name has no spaces). Print the table, one team per line, as rank name points goal_difference, where rank runs 1, 2, 3, ... with no shared ranks.
Sample test
Input
4 River 30 25 10 Boca 30 22 7 Tigre 28 20 10 Lanus 30 25 10
Expected output
1 Lanus 30 15 2 River 30 15 3 Boca 30 15 4 Tigre 28 10
Your answer is also checked against 3 hidden tests.
Need a hint?
Python can sort by a tuple key. To sort a number from high to low, use its negative.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
