ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(sorted([3, 1, 2], key=lambda x: -x)[0], max([3, 1, 2], key=lambda x: -x))
  1. A. 1 3
  2. B. 3 3
  3. C. 1 1
  4. D. 3 1

Correct answer: D. 3 1

Sorting by -x puts the largest value first, so the first item is 3. max by key -x returns the element whose negation is largest, which is 1.

More Python Programming questions

Exams that ask this topic