On this page
  1. itertools.tee
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

itertools.tee

Prev: itertools.takewhile | Up: itertools | Next: itertools.zip_longest
Rel: itertools.accumulate, itertools.batched, itertools.chain, itertools.combinations
Ref: docs.python.org — itertools.tee
Tags: #public #python3 #stdlib #itertools


Import

import itertools
from itertools import tee

Signature & Overview

itertools.tee(iterable, n=2, /)

Returns a tuple of n independent iterators.

Usage

from itertools import tee

it1, it2 = tee((x * 10 for x in range(3)), 2)
assert list(it1) == [0, 10, 20]
assert list(it2) == [0, 10, 20]

Gotchas

REPL Inspect

from itertools import tee
help(tee)

Linked from

Related notes