ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
import itertools
a, b = itertools.tee(iter([1, 2, 3]))
next(a); next(a)
print(list(b), list(a))
  1. A. [3] [3]
  2. B. [1, 2, 3] [1, 2, 3]
  3. C. [] [3]
  4. D. [1, 2, 3] [3]

Correct answer: D. [1, 2, 3] [3]

tee gives two independent iterators over the same source, buffering values one of them has not consumed yet; advancing a twice does not affect b.

More Python Programming questions

Exams that ask this topic