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
cef40c34
Kaydet (Commit)
cef40c34
authored
Ock 24, 2010
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 7764: Improve recipe for itertools.consume().
üst
495517cd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
1 deletion
+14
-1
itertools.rst
Doc/library/itertools.rst
+14
-1
No files found.
Doc/library/itertools.rst
Dosyayı görüntüle @
cef40c34
...
@@ -641,7 +641,13 @@ which incur interpreter overhead.
...
@@ -641,7 +641,13 @@ which incur interpreter overhead.
def consume(iterator, n):
def consume(iterator, n):
"Advance the iterator n-steps ahead. If n is none, consume entirely."
"Advance the iterator n-steps ahead. If n is none, consume entirely."
collections.deque(islice(iterator, n), maxlen=0)
# The technique uses objects that consume iterators at C speed.
if n is None:
# feed the entire iterator into a zero-length deque
collections.deque(iterator, maxlen=0)
else:
# advance to the emtpy slice starting at position n
next(islice(iterator, n, n), None)
def nth(iterable, n, default=None):
def nth(iterable, n, default=None):
"Returns the nth item or a default value"
"Returns the nth item or a default value"
...
@@ -751,3 +757,10 @@ which incur interpreter overhead.
...
@@ -751,3 +757,10 @@ which incur interpreter overhead.
# unique_justseen('AAAABBBCCDAABBB') --> A B C D A B
# unique_justseen('AAAABBBCCDAABBB') --> A B C D A B
# unique_justseen('ABBCcAD', str.lower) --> A B C A D
# unique_justseen('ABBCcAD', str.lower) --> A B C A D
return imap(next, imap(itemgetter(1), groupby(iterable, key)))
return imap(next, imap(itemgetter(1), groupby(iterable, key)))
Note, many of the above recipes can be optimized by replacing global lookups
with local variables defined as default values. For example, the
*dotproduct* recipe can be written as:
def dotproduct(vec1, vec2, sum=sum, imap=imap, mul=operator.mul):
return sum(imap(mul, vec1, vec2))
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