PY-22

Order Records by Several Keys

  • Medium
  • Records and Ordering
  • Python

Task

Write order_records(records). Each item in records is a dictionary with a string group, a numeric score, and a string name.

Return a new list ordered by these keys, in this exact order:

  1. group ascending;
  2. score descending within each group;
  3. name ascending when both earlier keys tie.

The input list and its dictionaries must not be changed. The result keeps the original record dictionaries, only changing their list order.

Example

The name decides the final tie inside group a; the score direction remains descending.

Your implementation

Edit solution.py and keep this function name and signature:

Return a new list containing the original dictionaries in the stated order. Do not use an ID or source position as an extra ordering rule, print anything, or mutate the inputs.