Skip to content
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

GH-98363: Add itertools.batched() #98364

Merged
merged 24 commits into from
Oct 17, 2022
Merged

Conversation

rhettinger
Copy link
Contributor

@rhettinger rhettinger commented Oct 17, 2022

@rhettinger rhettinger added type-feature A feature request or enhancement 3.12 bugs and security fixes labels Oct 17, 2022
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

I agree with adding this, just a few small comments.

Lib/test/test_itertools.py Outdated Show resolved Hide resolved
Modules/itertoolsmodule.c Show resolved Hide resolved
Modules/itertoolsmodule.c Show resolved Hide resolved
@rhettinger rhettinger added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 17, 2022
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @rhettinger for commit b9cbb46 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 17, 2022
@rhettinger rhettinger merged commit de3ece7 into python:main Oct 17, 2022
Roughly equivalent to::

def batched(iterable, n):
# batched('ABCDEFG', 3) --> ABC DEF G
Copy link
Member

Choose a reason for hiding this comment

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

Maybe tweak the example so it cannot be misunderstood as "return 3 batches"?

Choose a reason for hiding this comment

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

Suggested change
# batched('ABCDEFG', 3) --> ABC DEF G
# list(batched('ABCDEFG', 3)) --> [['A', 'B', 'C'], ['D', 'E', 'F'], ['G']]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants