import itertools


def batch_iterator(n, iterable, fillvalue=None):
    """
    Produces batches of size n over the elements in iterable.
    :param n: batch_size
    :param iterable: items
    :param fillvalue: value to complete las batch
    :return: iterator of batches
    """
    args = [iter(iterable)] * n
    return itertools.zip_longest(fillvalue=fillvalue, *args)