Describing itertools.tee(itr, n=2)
- The
takewhilefunction is used to repeat an iterableitrannamount of times - This iterable is based on the
itrparameter - This number of times is based on the
nparameter - The
nparameter is optional and defaults to teereturns an iterator ofniterators 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
3References
Previous
Next