ProgrammingHardGATE CS · Product-company placement

What is printed? (Output lines are shown separated by " / ".)

What is printed? (Output lines are shown separated by " / ".)
it = iter([1, 2, 3, 4, 5, 6])
print([(a, b) for a, b in zip(it, it)], [x for x in iter([1, 2, 3]) if x != 2])
c = iter("abcdef")
print(list(zip(c, c, c)))
  1. A. [(1, 2), (3, 4), (5, 6)] [1, 3] / [('a', 'b', 'c'), ('d', 'e', 'f')]
  2. B. [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)] [1, 3] / [('a', 'a', 'a')]
  3. C. [(1, 2), (3, 4), (5, 6)] [1, 3] / [('a', 'd'), ('b', 'e'), ('c', 'f')]
  4. D. [(1, 2), (3, 4), (5, 6)] [1, 2, 3] / [('a', 'b', 'c'), ('d', 'e', 'f')]

Correct answer: A. [(1, 2), (3, 4), (5, 6)] [1, 3] / [('a', 'b', 'c'), ('d', 'e', 'f')]

Passing the SAME iterator several times to zip makes each tuple pull consecutive items, which groups the stream into chunks of 2 (or 3).

More Python Programming questions

Exams that ask this topic