GH-98363: Add itertools.batched() by rhettinger · Pull Request #98364 · python/cpython

@rhettinger

@rhettinger

JelleZijlstra

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.

@rhettinger

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>

@rhettinger

@rhettinger

@rhettinger

@rhettinger

@rhettinger

@rhettinger

@rhettinger

@rhettinger

@rhettinger

@bedevere-bot

🤖 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.

@rhettinger

TeamSpen210

sweeneyde

@rhettinger

gvanrossum

Roughly equivalent to::

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

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.

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