Read an iterable in bounded pieces. Inputs may be one-shot generators.

Prototype: running_totals(values) returns a generator/iterator yielding cumulative sums. [2, -1, 4] -> 2, 1, 5; empty input yields nothing. Consume values only as outputs are requested.

Final: batches(values, size) returns a generator/iterator yielding fresh lists containing at most size consecutive input items. A final short batch is included; empty input yields nothing. batches(range(5), 2) -> [0, 1], [2, 3], [4]. size is an integer; a size less than 1 raises ValueError when iteration starts (earlier is also acceptable). Construction must not consume the source, and requesting the first batch must consume only that batch. Do not precompute the full input. Buffer at most one batch, using O(size) additional storage.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.