Skip to content

Sync itertools-in-python3 with the full update (pairwise, batched) - #853

Merged
martin-martin merged 3 commits into
masterfrom
maintenance/python-itertools-20260918
Oct 15, 2026
Merged

martin-martin merged 3 commits into
masterfrom
maintenance/python-itertools-20260918

Conversation

@realpython-bot

@realpython-bot realpython-bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

Companion sync for the full update of Python itertools By Example. The article now teaches pairwise() and batched() inside its two worked scripts, so the materials need to match.

What changed

  • itertools-in-python3/sp500.py: daily gains are computed with it.pairwise(prices) instead of zip(prices[1:], prices, strict=False), and max_gain passes zdp as the reduce() initial value, matching max_loss and the article.
  • itertools-in-python3/swimmers.py: the relay teams use it.batched(sorted_by_time, 4) instead of the grouper() recipe plus islice(), so grouper() is removed. _median() now iterates its own times argument instead of reading row["Times"] from the enclosing scope, a bug a reader reported in the comments.
  • itertools-in-python3/README.md: requires Python 3.12 or later because of batched(), and the interpreter note names python3.15 / python315, matching the article's dependencies: python==3.15.0.

Both scripts are standard library only, so there are no pins to move.

How it was verified

  • On Python 3.15.0, sp500.py prints Max gain: 11.58% on 2008-10-13 / Max loss: -20.47% on 1987-10-19 / Longest growth streak: 14 days (1971-03-26 to 1971-04-15), byte-for-byte the output in the README and the article.
  • On Python 3.15.0, swimmers.py prints the eight relay-team lines exactly as shown in the README and the article.
  • uvx ruff@0.14.1 format --check itertools-in-python3 reports both files already formatted.
  • uvx ruff@0.14.1 check itertools-in-python3 passes.

Links

🤖 Generated with Claude Code

RP Maintenance Bot and others added 2 commits September 18, 2026 06:19
Sync the scripts with the full update of Python itertools By Example:
sp500.py computes gains with itertools.pairwise() and passes zdp as the
reduce() initial value, swimmers.py builds relay teams with
itertools.batched() and fixes _median() to iterate its own argument.
The README now requires Python 3.12+ and names python3.15.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@realpython-bot realpython-bot changed the title Sync itertools-in-python3 with the updated tutorial Sync itertools-in-python3 with the full update (pairwise, batched) Oct 15, 2026

@martin-martin martin-martin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@martin-martin
martin-martin merged commit 546f12a into master Oct 15, 2026
1 check passed
@martin-martin
martin-martin deleted the maintenance/python-itertools-20260918 branch October 15, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants