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

Quiz: Sorting, heapq and bisect · Question 1 of 10

What does this print? (code)

What does this print?

data = [("b", 2), ("a", 2), ("c", 1)]
print(sorted(data, key=lambda t: (-t[1], t[0])))
  1. A.[('c', 1), ('a', 2), ('b', 2)]
  2. B.[('a', 2), ('b', 2), ('c', 1)]
  3. C.[('b', 2), ('a', 2), ('c', 1)]
  4. D.[('a', 2), ('c', 1), ('b', 2)]
Answer & explanation

Correct answer: [('a', 2), ('b', 2), ('c', 1)]

Higher number first (because of the minus sign), then letters A to Z when the numbers are equal.

Can you get the rest right without peeking?

Take the timed Quiz: Sorting, heapq and bisect quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →