Arrays · 23 / 23 Exercise Hard

Sort by several criteria

Objective

sort accepts a key function that returns a tuple: it sorts by the first element and, on a tie, by the second, and so on. To reverse a numeric criterion just flip its sign.

Instructions

  • Read an integer n and then n lines with name age.
  • Show the people sorted by age from oldest to youngest and, for equal age, alphabetically by name. One person per line, formatted as name age.
Input
3
Ana 30
Luis 25
Eva 30
Output
Ana 30
Eva 30
Luis 25

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise