ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print(sorted(['b', 'A', 'c', 'B'], key=str.casefold, reverse=True))
  1. A. ['c', 'b', 'A', 'B']
  2. B. ['A', 'b', 'B', 'c']
  3. C. ['c', 'b', 'B', 'A']
  4. D. ['c', 'A', 'b', 'B']

Correct answer: C. ['c', 'b', 'B', 'A']

Casefolded keys are b, a, c, b, so the descending order is c, then the two b's, then a. reverse=True keeps equal keys in their original order, so b (input index 0) comes before B (index 3).

More Python Programming questions

Exams that ask this topic