Sort by Grade, Then Name

Medium ⏱ 12 min 49% acceptance ★★★★☆ 4.2
Write rank_students(students) sorting a list of (name, grade) tuples by grade descending, breaking ties by name ascending — one sorted call with a lambda key building a compound tuple.

Examples

Example 1
Input
rank_students([('Zara', 90), ('Amit', 90), ('Bela', 95)])
Output
[('Bela', 95), ('Amit', 90), ('Zara', 90)]
Explanation

Bela leads; Amit beats Zara alphabetically at 90.

Constraints

  • Single sorted call.
  • No reverse=True — encode descending inside the key.

Topics

Lambda & Functionalmulti-key sort

Companies

MicrosoftGoldman SachsInfosys

Hints

Hint 1

Negate the numeric grade in the key tuple.

Hint 2

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

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