chunks
Split an iterator into chunks with n elements each.
def chunks(
it: iterator,
n: int
) - > generator
Split an iterator into chunks with n elements each. Warning: it must be an actual iterator, if you pass this a concrete sequence will get you repeating elements.
Parameters
| Name | Type | Description |
|---|---|---|
| it | iterator | The source iterator to be partitioned; must be a true iterator (e.g., via iter()) to avoid repeating elements. |
| n | int | The maximum number of elements to include in each yielded chunk. |
Returns
| Type | Description |
|---|---|
generator | A generator yielding lists, where each list contains up to n elements from the original iterator. |