Add batching function to itertools module

Normally itertools stays “minimal” and only provides these useful functions as recipes in the docs.

You can use more-itertools to get those recipes and lots more. https://more-itertools.readthedocs.io/
There are lots of ways to do batching in more-itertools, the chunked function seems closest to the batch function in this post.

See also Why does itertools have recipes?

5 Likes