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
3fa41d5a
Kaydet (Commit)
3fa41d5a
authored
Şub 26, 2008
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Docs for itertools.combinations(). Implementation in forthcoming checkin.
üst
b1d70e22
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
2 deletions
+44
-2
itertools.rst
Doc/library/itertools.rst
+44
-2
No files found.
Doc/library/itertools.rst
Dosyayı görüntüle @
3fa41d5a
...
...
@@ -76,6 +76,45 @@ loops that truncate the stream.
yield element
.. function:: combinations(iterable, r)
Return successive *r* length combinations of elements in the *iterable*.
Combinations are emitted in a lexicographic sort order. So, if the
input *iterable* is sorted, the combination tuples will be produced
in sorted order.
Elements are treated as unique based on their position, not on their
value. So if the input elements are unique, there will be no repeat
values within a single combination.
Each result tuple is ordered to match the input order. So, every
combination is a subsequence of the input *iterable*.
Example: ``combinations(range(4), 3) --> (0,1,2), (0,1,3), (0,2,3), (1,2,3)``
Equivalent to::
def combinations(iterable, r):
pool = tuple(iterable)
if pool:
n = len(pool)
vec = range(r)
yield tuple(pool[i] for i in vec)
while 1:
for i in reversed(range(r)):
if vec[i] == i + n-r:
continue
vec[i] += 1
for j in range(i+1, r):
vec[j] = vec[j-1] + 1
yield tuple(pool[i] for i in vec)
break
else:
return
.. versionadded:: 2.6
.. function:: count([n])
Make an iterator that returns consecutive integers starting with *n*. If not
...
...
@@ -311,9 +350,12 @@ loops that truncate the stream.
The leftmost iterators are in the outermost for-loop, so the output tuples
cycle in a manner similar to an odometer (with the rightmost element
changing on every iteration).
changing on every iteration). This results in a lexicographic ordering
so that if the inputs iterables are sorted, the product tuples are emitted
in sorted order.
Equivalent to (but without building the entire result in memory)::
Equivalent to the following except that the actual implementation does not
build-up intermediate results in memory::
def product(*args):
pools = map(tuple, args)
...
...
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