8000 Misc improvement to the docs for itertools by rhettinger · Pull Request #119529 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Misc improvement to the docs for itertools #119529

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 24, 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
Next Next commit
Simplify takewhile()
  • Loading branch information
rhettinger committed May 23, 2024
commit ed59bc4a706807acb105a1d4897bff0f90cad370
5 changes: 2 additions & 3 deletions Doc/library/itertools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,9 @@ loops that truncate the stream.
def takewhile(predicate, iterable):
# takewhile(lambda x: x<5, [1,4,6,4,1]) → 1 4
for x in iterable:
if predicate(x):
yield x
else:
if not predicate(x):
break
yield x

Note, the element that first fails the predicate condition is
consumed from the input iterator and there is no way to access it.
Expand Down
0