Repository navigation
Sync itertools-in-python3 with the full update (pairwise, batched) - #853
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Companion sync for the full update of Python itertools By Example. The article now teaches
pairwise()andbatched()inside its two worked scripts, so the materials need to match.What changed
itertools-in-python3/sp500.py: daily gains are computed withit.pairwise(prices)instead ofzip(prices[1:], prices, strict=False), andmax_gainpasseszdpas thereduce()initial value, matchingmax_lossand the article.itertools-in-python3/swimmers.py: the relay teams useit.batched(sorted_by_time, 4)instead of thegrouper()recipe plusislice(), sogrouper()is removed._median()now iterates its owntimesargument instead of readingrow["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 ofbatched(), and the interpreter note namespython3.15/python315, matching the article'sdependencies: python==3.15.0.Both scripts are standard library only, so there are no pins to move.
How it was verified
sp500.pyprintsMax 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.swimmers.pyprints the eight relay-team lines exactly as shown in the README and the article.uvx ruff@0.14.1 format --check itertools-in-python3reports both files already formatted.uvx ruff@0.14.1 check itertools-in-python3passes.Links
🤖 Generated with Claude Code