Leaderboard from a Score Dict

Medium ⏱ 12 min 52% acceptance ★★★★★ 4.5
Write leaderboard(scores) that converts a dict of player → score into a list of 'player: score' strings ordered by score descending, ties broken alphabetically — sorted on .items() with a lambda key, then a formatting pass.

Examples

Example 1
Input
leaderboard({'ana': 300, 'raj': 450, 'kim': 300})
Output
['raj: 450', 'ana: 300', 'kim: 300']
Explanation

raj leads; ana beats kim alphabetically at 300.

Constraints

  • Descending score, ascending name.
  • Output formatted strings.

Topics

Lambda & Functionalsorting dict items

Companies

Dream11MPLNetflix

Hints

Hint 1

key=lambda kv: (-kv[1], kv[0]).

Hint 2

f-strings for the final format.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.