ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: A. (1, 'b')

Reverse sorting on tuples compares the first fields, then the second. (1, 'b') is the largest tuple because 'b' is greater than 'a' when the first fields tie.

More Python Programming questions

Exams that ask this topic