ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
import itertools
print(list(itertools.islice(itertools.count(5, 2), 4)))
  1. A. [5, 6, 7, 8]
  2. B. [0, 2, 4, 6]
  3. C. [5, 7, 9, 11]
  4. D. [5, 7, 9]

Correct answer: C. [5, 7, 9, 11]

itertools.count(5, 2) is an infinite stream starting at 5, stepping by 2. islice takes the first 4 values: 5, 7, 9, 11.

More Python Programming questions

Exams that ask this topic