ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
from itertools import accumulate
print(list(accumulate([1, 2, 3], initial=0)), next(iter(sorted({3, 1, 2}))))
  1. A. [1, 3, 6] 1
  2. B. [0, 1, 3, 6] 3
  3. C. [0, 1, 2, 3] 1
  4. D. [0, 1, 3, 6] 1

Correct answer: D. [0, 1, 3, 6] 1

accumulate with initial=0 yields the running sums starting from 0. sorted of the set gives a list whose first element is 1.

More Python Programming questions

Exams that ask this topic