🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Counting Sort and Custom Sorting: all 13 questions

Quiz: Counting Sort and Custom Sorting · Question 5 of 13

Which Python key sorts students by marks high to low, then by name A to Z?

Which Python key sorts students by marks high to low, then by name A to Z?

  1. A.key=lambda s: (s.marks, s.name), reverse=True
  2. B.key=lambda s: (-s.marks, s.name)
  3. C.key=lambda s: (s.name, -s.marks)
  4. D.key=lambda s: -s.name
Answer & explanation

Correct answer: key=lambda s: (-s.marks, s.name)

Negating the marks reverses only that part of the order; the name still sorts ascending.

Can you get the rest right without peeking?

Take the timed Quiz: Counting Sort and Custom Sorting quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →