Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
c8223b09
Kaydet (Commit)
c8223b09
authored
Şub 18, 2009
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Generalize the itertools.tee() recipe.
üst
8367becc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
24 deletions
+24
-24
itertools.rst
Doc/library/itertools.rst
+24
-24
No files found.
Doc/library/itertools.rst
Dosyayı görüntüle @
c8223b09
...
@@ -137,7 +137,7 @@ loops that truncate the stream.
...
@@ -137,7 +137,7 @@ loops that truncate the stream.
return
return
indices = range(r)
indices = range(r)
yield tuple(pool[i] for i in indices)
yield tuple(pool[i] for i in indices)
while
1
:
while
True
:
for i in reversed(range(r)):
for i in reversed(range(r)):
if indices[i] != i + n - r:
if indices[i] != i + n - r:
break
break
...
@@ -187,7 +187,7 @@ loops that truncate the stream.
...
@@ -187,7 +187,7 @@ loops that truncate the stream.
return
return
indices = [0] * r
indices = [0] * r
yield tuple(pool[i] for i in indices)
yield tuple(pool[i] for i in indices)
while
1
:
while
True
:
for i in reversed(range(r)):
for i in reversed(range(r)):
if indices[i] != n - 1:
if indices[i] != n - 1:
break
break
...
@@ -610,28 +610,28 @@ loops that truncate the stream.
...
@@ -610,28 +610,28 @@ loops that truncate the stream.
.. function:: tee(iterable[, n=2])
.. function:: tee(iterable[, n=2])
Return *n* independent iterators from a single iterable.
The case where ``n==2``
Return *n* independent iterators from a single iterable.
Equivalent to::
is equivalent to::
def tee(iterable, n=2):
def tee(iterable):
it = iter(iterable)
def gen(next, data={}):
deques = [collections.deque() for i in range(n)]
for i in count(
):
def gen(mydeque
):
if i in data
:
while True
:
yield data.pop(i)
if not mydeque: # when the local deque is empty
else:
newval = next(it) # fetch a new value and
data[i] = next()
for d in deques: # load it to all the deques
yield data[i]
d.append(newval)
it = iter(iterable
)
yield mydeque.popleft(
)
return gen(it.next), gen(it.next
)
return tuple(gen(d) for d in deques
)
Note, o
nce :func:`tee` has made a split, the original *iterable* should not be
O
nce :func:`tee` has made a split, the original *iterable* should not be
used anywhere else; otherwise, the *iterable* could get advanced without
the tee
used anywhere else; otherwise, the *iterable* could get advanced without
objects being informed.
the tee
objects being informed.
Note, this member of the toolkit may require significant auxiliary storage
This itertool may require significant auxiliary storage (depending on how
(depending on how much temporary data needs to be stored). In general, if one
much temporary data needs to be stored). In general, if one iterator uses
iterator is going to use most or all of the data before the other iterator, it
most or all of the data before another iterator starts, it is faster to use
is faster to use
:func:`list` instead of :func:`tee`.
:func:`list` instead of :func:`tee`.
.. versionadded:: 2.4
.. versionadded:: 2.4
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment