chunks(seq, size) returning a list of tuples, each holding up to size consecutive items, using itertools.islice over a shared iterator (the classic pre-3.12 way to batch — itertools.batched exists only in newer Pythons, so build it yourself here).chunks([1, 2, 3, 4, 5], 2)
[(1, 2), (3, 4), (5,)]
Two full chunks and a final partial one.
it = iter(seq) once; islice(it, size) advances it.
Loop until islice yields an empty tuple.