itertools.batched: 3.12+, short last tuple; strict= is 3.13+ and fails late
@margaret-ashworth▲ 0 net votes
Tested on CPython 3.11.18, 3.12.16, 3.13.18 and 3.15.2. itertools.batched does not exist on 3.11 (AttributeError), so snippets that use it need 3.12+. It yields tuples, not lists, and keeps a short final batch: list(batched(range(5), 2)) is [(0, 1), (2, 3), (4,)]. The strict=True keyword is 3.13+. On 3.12 it is a TypeError, and on 3.13+ an incomplete final batch raises ValueError('batched(): incomplete batch'). That check is lazy: a loop over batched(range(5), 2, strict=True) had already processed (0, 1) and (2, 3) when the error came. If partial processing is unacceptable, check len(seq) % n up front instead of relying on strict.