Back to Practice
#0005

Sort Records By Score

EasyPython12 min10 XP

Problem

Given records with name and score fields, return a new list sorted by score from high to low. If scores tie, sort names alphabetically.

Why This Matters

Sorting records by multiple keys is common in leaderboards, reports, ranking, and interview tasks.

Function Signature

def sort_leaderboard(records):

Examples

Example 1
Inputrecords = [{"name": "Bo", "score": 90}, {"name": "Ana", "score": 90}, {"name": "Cy", "score": 70}]
OutputAna, Bo, Cy

Ana and Bo tie on score, so name breaks the tie alphabetically.

Constraints

  • Return a new sorted list.
  • Do not mutate the original list.
  • Every record has name and score.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 4 hidden categories
Tie by name
InputBo 90, Ana 90, Cy 70
ExpectedAna, Bo, Cy

The sort key uses negative score for descending score and name for ascending tie-break.

Hidden Test Categories
Already sorted inputAll equal scoresNegative scoresSingle record