ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print(max([('x', 5), ('y', 5)], key=lambda t: t[1]), min([('x', 5), ('y', 5)], key=lambda t: t[1]))
  1. A. ('y', 5) ('y', 5)
  2. B. ('x', 5) ('y', 5)
  3. C. ('y', 5) ('x', 5)
  4. D. ('x', 5) ('x', 5)

Correct answer: D. ('x', 5) ('x', 5)

max() and min() return the first item that reaches the extreme value when there is a tie. Both keys are 5, so both calls return the first tuple, ('x', 5).

More Python Programming questions

Exams that ask this topic