ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
from functools import reduce
print(reduce(lambda a, b: a * 10 + b, [1, 2, 3]), reduce(lambda a, b: a - b, [10, 2, 3]), reduce(lambda a, b: a - b, [], 0))
  1. A. 123 11 0
  2. B. 321 5 0
  3. C. 123 5 0
  4. D. 123 5 None

Correct answer: C. 123 5 0

reduce folds from the left, so 10 - 2 - 3 is 5 and not 10 - (2 - 3). With an empty list and an initial value of 0, reduce returns that initial value.

More Python Programming questions

Exams that ask this topic