ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import itertools
g = iter(range(10))
print(list(itertools.islice(g, 2, 7, 2)), next(g))
  1. A. [2, 4, 6] 7
  2. B. [2, 4, 6] 8
  3. C. [2, 4] 6
  4. D. [2, 4, 6] 6

Correct answer: A. [2, 4, 6] 7

islice(it, 2, 7, 2) yields the items at indices 2, 4 and 6 and stops without reading index 7. The next item left in the shared iterator is 7.

More Python Programming questions

Exams that ask this topic