def chunks ( iterable , size = 1 ) : iterator = iter ( iterable ) for element in iterator : yield chain ( [ element ] , islice ( iterator , size - 1 ) )
how to split the iterator object into chunks python
Splits iterator in chunks .
def chunks(iterable, size=1):
    """Splits iterator in chunks."""
    iterator = iter(iterable)

    for element in iterator:
        yield chain([element], islice(iterator, size - 1))