Visitar URL original
Misc improvement to the docs for itertools by rhettinger · Pull Request #119529 · python/cpython · GitHub
Skip to content
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
Improve comress() text and code equivalent.
  • Loading branch information
rhettinger committed May 23, 2024
commit 2a53903f72abfde520b0f34affe86c24f8b82098
6 changes: 3 additions & 3 deletions Doc/library/itertools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ loops that truncate the stream.
.. function:: compress(data, selectors)

Make an iterator that filters elements from *data* returning only those that
have a corresponding element in *selectors* that evaluates to ``True``.
Stops when either the *data* or *selectors* iterables has been exhausted.
have a corresponding element in *selectors* is true.
Stops when either the *data* or *selectors* iterables have been exhausted.
Roughly equivalent to::

def compress(data, selectors):
# compress('ABCDEF', [1,0,1,0,1,1]) → A C E F
return (d for d, s in zip(data, selectors) if s)
return (datum for datum, selector in zip(data, selectors) if selector)

.. versionadded:: 3.1

Expand Down