← Quiz: Counting Sort and Custom Sorting: all 13 questions
Quiz: Counting Sort and Custom Sorting · Question 1 of 13
What does this print? (code)
What does this print?
print(sorted(["bb", "a", "ccc", "dd"], key=len))
- A.['a', 'bb', 'dd', 'ccc']
- B.['a', 'dd', 'bb', 'ccc']
- C.['a', 'bb', 'ccc', 'dd']
- D.['ccc', 'bb', 'dd', 'a']
Answer & explanation
Correct answer: ['a', 'bb', 'dd', 'ccc']
Sorted by length; "bb" and "dd" have the same length, and the stable sort keeps "bb" first as in the input.
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 →