What is the output of the following Python code snippet?
from itertools import cycle, islice
print(list(islice(cycle([1, 2]), 4)))
print(list(islice(cycle([1, 2]), 4)))
Correct answer
C. [1, 2, 1, 2]
5 views
C. [1, 2, 1, 2]
5 views
cycle() repeats forever, islice stops it after four items.
Asked in: Python Interview Advanced
https://docs.python.org/3/library/index.htmlNot sure why the answer is C? Ask here and get an explanation.