(iterable, n)
| 23 | |
| 24 | |
| 25 | def batched(iterable, n): |
| 26 | # batched('ABCDEFG', 3) → ABC DEF G |
| 27 | if n < 1: |
| 28 | raise ValueError("n must be at least one") |
| 29 | iterator = iter(iterable) |
| 30 | while batch := list(itertools.islice(iterator, n)): |
| 31 | yield batch |
| 32 | |
| 33 | |
| 34 | xs = [ |
no outgoing calls
no test coverage detected