How to chunk (batch) an iterable in #Python:
it = iter(iterable)
chunks = iter(lambda: list(islice(it, CHUNK_SIZE)), )
It uses the little-known form of `iter()` with two arguments where it repeatedly call the first argument until it returns the sentinel value provided in the second.
This is incidentally what more_itertools.chunked does. But may be you're not allowed to add dependencies or something…
@isagalaev TIL about the two-argument form of ‘iter’
Server run by the main developers of the project It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!