scistag.common.iter_helper.batch_iter¶
- batch_iter(iterator, n, fast=False)[source]¶
Creates an iterator which returns elements in batches of size n from an iterator.
- Parameters
iterator – The iterator
n – The count of elements per batch
fast – If defined the whole iterator will be unwrapped into a list in “one go” which is usually like 3x-4x faster than iterative.
- Returns
The next batch.
Always a list of size n except for the last batch will contain the remaining elements.