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
9265dd72
Unverified
Kaydet (Commit)
9265dd72
authored
Nis 08, 2018
tarafından
Raymond Hettinger
Kaydeden (comit)
GitHub
Nis 08, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add a prepend() recipe to teach a chain() idiom (GH-6415)
üst
c87eb09d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
0 deletions
+13
-0
itertools.rst
Doc/library/itertools.rst
+5
-0
test_itertools.py
Lib/test/test_itertools.py
+8
-0
No files found.
Doc/library/itertools.rst
Dosyayı görüntüle @
9265dd72
...
@@ -688,6 +688,11 @@ which incur interpreter overhead.
...
@@ -688,6 +688,11 @@ which incur interpreter overhead.
"Return first n items of the iterable as a list"
"Return first n items of the iterable as a list"
return list(islice(iterable, n))
return list(islice(iterable, n))
def prepend(value, iterator):
"Prepend a single value in front of an iterator"
# prepend(1, [2, 3, 4]) -> 1 2 3 4
return chain([value], iterator)
def tabulate(function, start=0):
def tabulate(function, start=0):
"Return function(0), function(1), ..."
"Return function(0), function(1), ..."
return map(function, count(start))
return map(function, count(start))
...
...
Lib/test/test_itertools.py
Dosyayı görüntüle @
9265dd72
...
@@ -2198,6 +2198,11 @@ Samuele
...
@@ -2198,6 +2198,11 @@ Samuele
... "Return first n items of the iterable as a list"
... "Return first n items of the iterable as a list"
... return list(islice(iterable, n))
... return list(islice(iterable, n))
>>> def prepend(value, iterator):
... "Prepend a single value in front of an iterator"
... # prepend(1, [2, 3, 4]) -> 1 2 3 4
... return chain([value], iterator)
>>> def enumerate(iterable, start=0):
>>> def enumerate(iterable, start=0):
... return zip(count(start), iterable)
... return zip(count(start), iterable)
...
@@ -2350,6 +2355,9 @@ perform as purported.
...
@@ -2350,6 +2355,9 @@ perform as purported.
>>> take(10, count())
>>> take(10, count())
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(prepend(1, [2, 3, 4]))
[1, 2, 3, 4]
>>> list(enumerate('abc'))
>>> list(enumerate('abc'))
[(0, 'a'), (1, 'b'), (2, 'c')]
[(0, 'a'), (1, 'b'), (2, 'c')]
...
...
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