Skip to content

Instantly share code, notes, and snippets.

from itertools import islice, tee
def cut_chunks(iterable, size):
it = iter(iterable)
while True:
test_chunk, chunk = tee(islice(it, size))
try:
next(test_chunk)
yield chunk