ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: C. [(-1, 'a'), (-1, 'b'), (0, 'c')] (1, 'z')

Tuples compare by the first field and then the second. max keeps the larger tuple, (1, 'z'), since 'z' is larger than 'a'.

More Python Programming questions

Exams that ask this topic