ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
from itertools import accumulate
print(list(accumulate([1, 2, 3], lambda a, b: a * b)), list(accumulate('ab', initial='>')))
  1. A. [1, 2, 6] ['>', '>a', '>ab']
  2. B. [1, 3, 6] ['>', '>a', '>ab']
  3. C. [1, 2, 6] ['x', 'xa']
  4. D. [1, 2, 6] ['>', 'a', 'b']

Correct answer: A. [1, 2, 6] ['>', '>a', '>ab']

accumulate with a multiplying function gives running products 1, 2, 6. initial='>' puts the start value first, and each step appends the next character to the running string.

More Python Programming questions

Exams that ask this topic