def 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, ... : iterable
Copies of ``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
"""
# itercopy is included because documentation of itertools.tee isn't obvious
# to everyone
return tee(iterable, copies)
评论列表
文章目录