ProgrammingModerateTCS NQT · Accenture

What is printed?

What is printed?
import itertools
print(list(itertools.accumulate([3, 1, 4], initial=10)))
  1. A. [10, 3, 4, 8]
  2. B. [13, 14, 18]
  3. C. [10, 13, 14, 18]
  4. D. [3, 4, 8]

Correct answer: C. [10, 13, 14, 18]

accumulate with initial=10 yields the starting value first, then each running sum: 10, 13, 14, 18.

More Python Programming questions

Exams that ask this topic