Iteration Functions
itertools.tee()
Create n independent traversal positions over a shared source. Diverging consumption can require substantial buffering; do not independently consume the original iterator or use the derived iterators concurrently without synchronization.
Formal Syntax & Structure
python syntaxpython
itertools.tee(iterable, n=2, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| iterable | iterable | Input values, consumed as needed. |
| n | int | Requested count; see constraints in description. |
Return Value
tuple[iterator, ...]
The tuple[iterator, ...] result described above.
Working Example
Example Snippetpython
import itertoolsa,b=itertools.tee([1,2])print((list(a),list(b)))