ProgrammingModerateGATE CS · Product-company placement

What is printed?

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

Correct answer: A. [1, 3, 6, 10] ['a', 'b', 1] [5, 7, 9]

accumulate yields running totals, chain flattens one level (a string contributes its characters), and islice takes the first 3 values of the infinite count 5, 7, 9, ...

More Python Programming questions

Exams that ask this topic