← 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?
- A.key=lambda s: (s.marks, s.name), reverse=True
- B.key=lambda s: (-s.marks, s.name)
- C.key=lambda s: (s.name, -s.marks)
- 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 →