Data Structures & AlgorithmsModerateTCS NQT Digital · Python semantics

Problem: What does the following print?

Problem: What does the following print?
print(sorted(['b', 'B', 'a', 'A']))
  1. A. ['a', 'A', 'b', 'B']
  2. B. ['A', 'B', 'a', 'b']
  3. C. ['b', 'B', 'a', 'A']
  4. D. ['B', 'A', 'b', 'a']

Correct answer: B. ['A', 'B', 'a', 'b']

Uppercase letters have smaller code points than lowercase, so all capitals come first in code-point order.

More Coding Interview Problems questions

Exams that ask this topic