File size: 361 Bytes
256a159 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
from itertools import islice
try:
# batched is in 3.12
from itertools import batched
except ImportError:
def batched(iterable, n):
# batched('ABCDEFG', 3) --> ABC DEF G
if n < 1:
raise ValueError('n must be at least one')
it = iter(iterable)
while batch := tuple(islice(it, n)):
yield batch
|