ProgrammingModerateAccenture · Capgemini pattern

What is printed?

What is printed?
print(min([3, -4, 2], key=lambda v: v * v), max({"a": 3, "b": 1}), max("abc", "b", key=len))
  1. A. -4 a abc
  2. B. 2 a abc
  3. C. 2 b abc
  4. D. 2 b b

Correct answer: C. 2 b abc

min with key compares squares 9, 16, 4 and returns the original element with the smallest key: 2. max over a dict iterates its keys, not values, so it compares 'a' and 'b' and returns 'b'. With key=len, 'abc' (length 3) beats 'b'.

More Python Programming questions

Exams that ask this topic