All, pls see below test code about itertools.tee:
li = [x for x in range(10)]
ite = iter(li)
==================================================
it = itertools.tee(ite, 5)
>>> type(ite)
<type 'listiterator'>
>>> type(it)
<type 'tuple'>
>>> type(it[0])
<type 'itertools.tee'>
>>>
>>> list(ite)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(it[0]) # here I got nothing after 'list(ite)', why?
[]
>>> list(it[1])
[]
====================play again===================
>>> ite = iter(li)
it = itertools.tee(ite, 5)
>>> list(it[1])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(it[2])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(it[3])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(it[4])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(ite)
[] # why I got nothing? and why below line still have the data?
>>> list(it[0])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(it[0])
[]
====================play again===================
>>> ite = iter(li)
itt = itertools.tee(it[0], 5) # tee the iter's tee[0].
>>> list(itt[0])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(itt[1])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(it[0])
[] # why this has no data?
>>> list(it[1])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(ite)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
My quesion is
1.how tee works and why sometimes the original iter 'has data' and other time it has not?
2.can I keep an iter deep copy as a "status seed" to keep the raw iterator status and tee it to use later?
3.can I swap 2 iters or 2 itertools.tee?
Thanks!