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
a1d61d04
Kaydet (Commit)
a1d61d04
authored
Nis 10, 2010
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixup new itertools recipes.
üst
343314a1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
itertools.rst
Doc/library/itertools.rst
+7
-3
No files found.
Doc/library/itertools.rst
Dosyayı görüntüle @
a1d61d04
...
@@ -796,7 +796,7 @@ which incur interpreter overhead.
...
@@ -796,7 +796,7 @@ which incur interpreter overhead.
pools = map(tuple, args) * kwds.get('repeat', 1)
pools = map(tuple, args) * kwds.get('repeat', 1)
return tuple(random.choice(pool) for pool in pools)
return tuple(random.choice(pool) for pool in pools)
def random_permuation(iterable, r=None):
def random_permu
t
ation(iterable, r=None):
"Random selection from itertools.permutations(iterable, r)"
"Random selection from itertools.permutations(iterable, r)"
pool = tuple(iterable)
pool = tuple(iterable)
r = len(pool) if r is None else r
r = len(pool) if r is None else r
...
@@ -805,12 +805,16 @@ which incur interpreter overhead.
...
@@ -805,12 +805,16 @@ which incur interpreter overhead.
def random_combination(iterable, r):
def random_combination(iterable, r):
"Random selection from itertools.combinations(iterable, r)"
"Random selection from itertools.combinations(iterable, r)"
pool = tuple(iterable)
pool = tuple(iterable)
return tuple(sorted(random.sample(pool, r), key=pool.index))
n = len(pool)
indices = sorted(random.sample(xrange(n), r))
return tuple(pool[i] for i in indices)
def random_combination_with_replacement(iterable, r):
def random_combination_with_replacement(iterable, r):
"Random selection from itertools.combinations_with_replacement(iterable, r)"
"Random selection from itertools.combinations_with_replacement(iterable, r)"
pool = tuple(iterable)
pool = tuple(iterable)
return tuple(sorted(imap(random.choice, [pool]*r), key=pool.index))
n = len(pool)
indices = sorted(random.randrange(n) for i in xrange(r))
return tuple(pool[i] for i in indices)
Note, many of the above recipes can be optimized by replacing global lookups
Note, many of the above recipes can be optimized by replacing global lookups
with local variables defined as default values. For example, the
with local variables defined as default values. For example, the
...
...
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