ProgrammingVery hardCodeforces-style · placement coding round

What is printed?

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

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

[iter(...)] * 2 repeats one iterator object, so zip takes consecutive pairs from the same iterator. The pairs are (0, 1), (2, 3) and (4, 5).

More Python Programming questions

Exams that ask this topic