ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
from itertools import accumulate
print(list(accumulate([2, 3, 4], lambda a, b: a * b)), list(accumulate([1, -1, 2])))
  1. A. [2, 6, 24] [1, -1, 2]
  2. B. [2, 5, 9] [1, 0, 2]
  3. C. [2, 6, 24] [1, 0, 1]
  4. D. [2, 6, 24] [1, 0, 2]

Correct answer: D. [2, 6, 24] [1, 0, 2]

accumulate applies the function to the running value and the next item. The product path is 2, 6, 24, and the running sum of [1, -1, 2] is 1, 0, 2.

More Python Programming questions

Exams that ask this topic