8000 Misc cleanups and wording improvements for the itertools docs by rhettinger · Pull Request #119626 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Misc cleanups and wording improvements for the itertools docs #119626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
.
  • Loading branch information
rhettinger committed May 27, 2024
commit d3e6800254f6d944fe93821630d7715265050913
4 changes: 4 additions & 0 deletions Doc/library/itertools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,13 @@ loops that truncate the stream.
def combinations(iterable, r):
# combinations('ABCD', 2) → AB AC AD BC BD CD
# combinations(range(4), 3) → 012 013 023 123

pool = tuple(iterable)
n = len(pool)
if r > n:
return
indices = list(range(r))

yield tuple(pool[i] for i in indices)
while True:
for i in reversed(range(r)):
Expand Down Expand Up @@ -285,11 +287,13 @@ loops that truncate the stream.

def combinations_with_replacement(iterable, r):
# combinations_with_replacement('ABC', 2) → AA AB AC BB BC CC

pool = tuple(iterable)
n = len(pool)
if not n and r:
return
indices = [0] * r

yield tuple(pool[i] for i in indices)
while True:
for i in reversed(range(r)):
Expand Down
0