ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(sorted(['b', 'B', 'a'], key=lambda s: (s.lower(), s)))
  1. A. ['a', 'B', 'b']
  2. B. ['c', 'B', 'b']
  3. C. ['B', 'a', 'b']
  4. D. ['b', 'a', 'd']

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

The key is a tuple of the lowercase letter and the original string. a comes first, and within the b group, uppercase B has the smaller code point, so B comes before b.

More Python Programming questions

Exams that ask this topic