Yield successive fixed-size chunks from an iterable without missing the last partial batch.
Constraints
Example
>>> list(batch_iterator([1, 2, 3, 4, 5], 2))
[[1, 2], [3, 4], [5]]
>>> list(batch_iterator('abcdef', 3))
[['a', 'b', 'c'], ['d', 'e', 'f']]
>>> list(batch_iterator([], 5))
[]
Recent Submissions
No submissions yet — hit Run Tests to try!
Hints