def zip_aligned(*args):
    """
    Similar to the zip built-in, but raises an ValueError if one sequence
    terminates before the others.
    """
    args = map(iter, args)
    yield from zip(*args)
    for idx, it in enumerate(args):
        try:
            next(it)
        except StopIteration:
            pass
        else:
            raise ValueError('the %s-th iterator is still running' % idx)
