import itertools


def chunk(it, n):
    """Yield successive n-sized chunks from it.

    >>> l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    >>> list(chunk(l, 3))
    [(1, 2, 3), (4, 5, 6), (7, 8, 9)]
    >>> list(chunk(l, 2))
    [(1, 2), (3, 4), (5, 6), (7, 8), (9,)]
    """
    it = iter(it)
    return iter(lambda: tuple(itertools.islice(it, n)), ())