ProgrammingModerateTCS NQT · Accenture

What is printed?

What is printed?
from itertools import accumulate
a = [3, 1, 4, 1, 5, 9, 2]
print(list(accumulate(a, max)), list(accumulate(a, lambda x, y: x * y))[-1])
  1. A. [3, 3, 4, 4, 5, 9, 9] 1081
  2. B. [3, 1, 4, 1, 5, 9, 2] 1080
  3. C. [3, 4, 4, 5, 5, 9, 9] 1080
  4. D. [3, 3, 4, 4, 5, 9, 9] 1080

Correct answer: D. [3, 3, 4, 4, 5, 9, 9] 1080

accumulate with max keeps the running maximum, and with multiplication it keeps running products. The product of all seven values is 1080.

More Python Programming questions

Exams that ask this topic