ProgrammingHardProduct-company MCQ pattern

What is printed on the second line?

What is printed on the second line?
print(''.join(sorted('banana')))
print(sorted('Banana', key=str.lower))
print(sorted(['b10', 'b9', 'a']))
  1. A. ['B', 'a', 'a', 'a', 'n', 'n']
  2. B. ['a', 'a', 'a', 'n', 'n', 'B']
  3. C. ['a', 'a', 'a', 'B', 'n', 'n']
  4. D. ['a', 'a', 'a', 'B', 'n']

Correct answer: C. ['a', 'a', 'a', 'B', 'n', 'n']

Sorting with key=str.lower compares the lowercase forms, so the three a's come first, then B, then the two n's. Without a key, uppercase letters would sort before all lowercase letters, which is the trap in the second option.

More Python Programming questions

Exams that ask this topic