def chunk_iter(iterable, chunk_size):
    '''A generator that yields chunks of iterable, chunk_size at a time. '''
    while True:
        chunk = []
        try:
            for _ in range(chunk_size): chunk.append(next(iterable))
            yield chunk
        except StopIteration:
            if chunk: yield chunk
            break
def chunk_iter ( iterable , chunk_size ) : while True : chunk = [ ] try : for _ in range ( chunk_size ) : chunk . append ( next ( iterable ) ) yield chunk except StopIteration : if chunk : yield chunk break
A generator that yields chunks of iterable, chunk_size at a time.