ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
import itertools
print(list(itertools.islice(itertools.cycle('ab'), 5)), list(itertools.repeat(7, 2)))
  1. A. ['a', 'b', 'a', 'b', 'a'] [7]
  2. B. ['a', 'b', 'a', 'b', 'b'] [7, 7]
  3. C. ['a', 'b', 'a', 'b'] [7, 7]
  4. D. ['a', 'b', 'a', 'b', 'a'] [7, 7]

Correct answer: D. ['a', 'b', 'a', 'b', 'a'] [7, 7]

cycle repeats the sequence forever, and islice takes five items. repeat(7, 2) yields 7 twice.

More Python Programming questions

Exams that ask this topic