ProgrammingHardProduct-company MCQ pattern

What is printed?

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

Correct answer: B. [(1, 2), (3, 4)]

Both arguments are the SAME iterator, so each tuple takes two values one after the other: (1, 2), then (3, 4). For the third tuple, 5 is taken but the second pull fails, so zip stops and 5 is dropped.

More Python Programming questions

Exams that ask this topic