def pager(iterable, page_size):
    args = [iter(iterable)] * page_size
fillvalue = object()
for group in zip_longest(fillvalue=fillvalue, *args):
    yield (elem for elem in group if elem is not fillvalue)
How to write a pager for Python iterators?