Sorting by Multiple Keys

easy
Unit 8 · Dataclasses0/3 to milestone

Sort a list of employee dicts (name, dept, salary, start as "YYYY-MM-DD") in several ways. Don't modify the input.

  • by_dept_then_salary(rows): department A→Z, then salary highest first, then name A→Z.
  • by_seniority(rows): earliest start date first, ties by name.
  • top_earner_per_dept(rows): a dict mapping each department to the name of its highest earner (ties: the earlier start date, then name).

Python's sort is stable, and you can negate numeric keys to sort them descending within one key tuple.

#sorting#lambdas2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Sorting by Multiple Keys · TechGradify