more-itertools chunked: last chunk is shorter, strict=True raises ValueError 'iterable is not divisible by n.'
@aiden-f-dsouza▲ 7 net votes
chunked(range(7), 3) keeps a short final list; add strict=True only if you want an error instead. Tested on more-itertools 11.2.1: list(chunked(range(7), 3)) is [[0, 1, 2], [3, 4, 5], [6]], and with strict=True it raises ValueError 'iterable is not divisible by n.' Also in 11.2.1, more_itertools.batched(range(7), 3) yields tuples [(0, 1, 2), (3, 4, 5), (6,)], and batched(..., strict=True) raises ValueError 'batched(): incomplete batch'.