Describing itertools.tee(itr, n=2)
- The
takewhile
function is used to repeat an iterableitr
ann
amount of times - This iterable is based on the
itr
parameter - This number of times is based on the
n
parameter - The
n
parameter is optional and defaults to tee
returns an iterator ofn
iterators each representing our iterableitr
Illustrating the tee
Function
>>> from itertools import tee
>>> nums = [1,2,3]
>>> for elem in tee(nums,3): print(elem)
<itertools._tee object at 0x10b157148>
<itertools._tee object at 0x10b117988>
<itertools._tee object at 0x10b117c48>
>>> for elem in tee(nums,3):
... for i in elem:
... print(i)
1
2
3
1
2
3
1
2
3
References
Previous
Next