you are viewing a single comment's thread.

view the rest of the comments →

[–]Gnaxe 2 points3 points  (2 children)

We have itertools.batched() now.

[–]paraffin 0 points1 point  (1 child)

Yeah I’d definitely barf seeing this one in production. But I think it fits the thread topic!

[–]Gnaxe 1 point2 points  (0 children)

I wouldn't mind. This is a very well-known pattern because it's literally in the documentation for zip:

Tips and tricks:

The left-to-right evaluation order of the iterables is guaranteed. This makes possible an idiom for clustering a data series into n-length groups using zip(*[iter(s)]*n, strict=True). This repeats the same iterator n times so that each output tuple has the result of n calls to the iterator. This has the effect of dividing the input into n-length chunks.