ProgrammingVery hardInfosys HackWithInfy · TCS CodeVita

What is printed?

What is printed?
it = iter(range(7))
print(list(zip(it, it)), list(it))
  1. A. [(0, 1), (2, 3), (4, 5)] [6]
  2. B. [(0, 1), (2, 3), (4, 5), (6, None)] []
  3. C. [(0, 1), (2, 3), (4, 5)] [6, 7]
  4. D. [(0, 1), (2, 3), (4, 5)] []

Correct answer: D. [(0, 1), (2, 3), (4, 5)] []

zip pulls from the first iterator before the second, so the value 6 taken from the first iterator is discarded when the second one is exhausted. The shared iterator ends empty.

More Python Programming questions

Exams that ask this topic