🎙 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 1 of 13

What does this print? (code)

What does this print?

print(sorted(["bb", "a", "ccc", "dd"], key=len))
  1. A.['a', 'bb', 'dd', 'ccc']
  2. B.['a', 'dd', 'bb', 'ccc']
  3. C.['a', 'bb', 'ccc', 'dd']
  4. 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 →