ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(max(range(5), key=lambda x: -abs(x - 2)), min(range(5), key=lambda x: abs(x - 2)))
  1. A. 2 2
  2. B. 0 4
  3. C. 2 0
  4. D. 4 4

Correct answer: A. 2 2

-abs(x - 2) is largest at x = 2, and abs(x - 2) is smallest at x = 2 as well.

More Python Programming questions

Exams that ask this topic