def combine(seq0, seq1, f):
    """Takes two generators or iterators and a combiner function f. The ith
    term of combiner function is the ith terms of both seq0 and seq1 combined by
    function f. The length of combiner should be the *longer* of the two
    sequences. The shorter sequence is padded with 0s.

    >>> gen = combine(iter([0, 1]), iter([0, 1, 2, 3]), lambda x, y: x+y)
    >>> for i in gen:
    ...   print(i)
    ...
    0
    2
    2
    3
    """
    def trynext(seq):
        try:
            return next(seq)
        except StopIteration:
            return None
    while True:
        n1, n2 = trynext(seq0), trynext(seq1)
        if n1 is None and n2 is None:
            raise StopIteration
        yield f(n1 or 0, n2 or 0)