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
5d12faa5
Kaydet (Commit)
5d12faa5
authored
Eki 30, 2011
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge
üst
385c8036
6f45d18c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
10 deletions
+19
-10
functions.rst
Doc/library/functions.rst
+3
-3
itertools.rst
Doc/library/itertools.rst
+16
-7
No files found.
Doc/library/functions.rst
Dosyayı görüntüle @
5d12faa5
...
@@ -1375,10 +1375,10 @@ are always available. They are listed here in alphabetical order.
...
@@ -1375,10 +1375,10 @@ are always available. They are listed here in alphabetical order.
def zip(*iterables):
def zip(*iterables):
# zip('ABCD', 'xy') --> Ax By
# zip('ABCD', 'xy') --> Ax By
sentinel = object()
sentinel = object()
itera
ble
s = [iter(it) for it in iterables]
itera
tor
s = [iter(it) for it in iterables]
while itera
ble
s:
while itera
tor
s:
result = []
result = []
for it in itera
ble
s:
for it in itera
tor
s:
elem = next(it, sentinel)
elem = next(it, sentinel)
if elem is sentinel:
if elem is sentinel:
return
return
...
...
Doc/library/itertools.rst
Dosyayı görüntüle @
5d12faa5
...
@@ -595,16 +595,25 @@ loops that truncate the stream.
...
@@ -595,16 +595,25 @@ loops that truncate the stream.
iterables are of uneven length, missing values are filled-in with *fillvalue*.
iterables are of uneven length, missing values are filled-in with *fillvalue*.
Iteration continues until the longest iterable is exhausted. Equivalent to::
Iteration continues until the longest iterable is exhausted. Equivalent to::
def zip_longest(*args, fillvalue=None):
class ZipExhausted(Exception):
pass
def zip_longest(*args, **kwds):
# zip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
# zip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
fillvalue = kwds.get('fillvalue')
yield counter() # yields the fillvalue, or raises IndexError
counter = len(args) - 1
def sentinel():
nonlocal counter
if not counter:
raise ZipExhausted
counter -= 1
yield fillvalue
fillers = repeat(fillvalue)
fillers = repeat(fillvalue)
iters = [chain(it, sentinel(), fillers) for it in args]
iter
ator
s = [chain(it, sentinel(), fillers) for it in args]
try:
try:
for tup in zip(*iters)
:
while iterators
:
yield tup
yield tup
le(map(next, iterators))
except
IndexError
:
except
ZipExhausted
:
pass
pass
If one of the iterables is potentially infinite, then the :func:`zip_longest`
If one of the iterables is potentially infinite, then the :func:`zip_longest`
...
...
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