npstreams.itercopy

npstreams.itercopy(iterable, copies=2)

Split iterable into ‘copies’. Once this is done, the original iterable should not be used again.

Parameters
  • iterable (iterable) – Iterable to be split. Once it is split, the original iterable should not be used again.

  • copies (int, optional) – Number of copies. Also determines the number of returned iterables.

Returns

iter1, iter2, … – Copies of iterable.

Return type

iterable

Examples

By rebinding the name of the original iterable, we make sure that it will never be used again.

>>> from npstreams import itercopy
>>> evens = (2*n for n in range(1000))
>>> evens, evens_copy = itercopy(evens, copies = 2)

See also

itertools.tee

equivalent function