← 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])))
- A.[('c', 1), ('a', 2), ('b', 2)]
- B.[('a', 2), ('b', 2), ('c', 1)]
- C.[('b', 2), ('a', 2), ('c', 1)]
- 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 →