def chunks ( iterable , chunk ) : for i in range ( 0 , len ( iterable ) , chunk ) : yield iterable [ i : i + chunk ]
how to slice iterables in python
Yield successive n - sized chunks from an iterable .
def chunks(iterable, chunk):
    """Yield successive n-sized chunks from an iterable."""
    for i in range(0, len(iterable), chunk):
        yield iterable[i:i + chunk]