ProgrammingHardGATE CS · Product-company placement

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, [], 7), reduce(max, [3, 9, 2]))
  1. A. 6 7 9
  2. B. 123 0 9
  3. C. 123 7 9
  4. D. 321 7 9

Correct answer: C. 123 7 9

reduce folds left: ((1*10 + 2)*10 + 3) = 123. With an empty sequence it returns the initializer 7. reduce(max, ...) keeps the larger value at each step.

More Python Programming questions

Exams that ask this topic