loading…
Write a generator chunked(iterable, n) that yields lists of up to n items. It must work on any iterable, including an endless one, without reading it all first.
list(chunked(range(7), 3)) -> [[0, 1, 2], [3, 4, 5], [6]]
Stuck on the idea itself? The python fluency lesson walks through the pattern from scratch.