ProgrammingHardCodeforces-style · placement coding round

What is printed?

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

Correct answer: B. [(3, 'a'), (2, 'b'), (1, 'z')]

reverse=True sorts the tuples from largest to smallest, comparing the number first and then the letter. So (3, 'a') comes first, followed by (2, 'b') and (1, 'z').

More Python Programming questions

Exams that ask this topic