ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
import itertools
print(list(itertools.accumulate([1, 2, 3, 4])), list(itertools.accumulate('ab')), sum(itertools.islice(itertools.count(5), 3)))
  1. A. [1, 3, 6, 10] ['a', 'b'] 18
  2. B. [1, 2, 3, 4] ['a', 'ab'] 18
  3. C. [1, 3, 6, 10] ['a', 'ab'] 18
  4. D. [1, 3, 6, 10] ['a', 'ab'] 15

Correct answer: C. [1, 3, 6, 10] ['a', 'ab'] 18

accumulate gives running totals, so strings concatenate as well. count starting at 5 supplies 5, 6 and 7 for islice, which sum to 18.

More Python Programming questions

Exams that ask this topic