(*iters)
cartesian product generator

    Notes
    =====

    Unlike itertools.product, it works also with iterables which do not fit
    in memory. See http://bugs.python.org/issue10109

    Author: Fernando Sumudu
    with small changes
cartesian product generator
cartesian product generator
def _product(*iters):
    """
    cartesian product generator

    Notes
    =====

    Unlike itertools.product, it works also with iterables which do not fit
    in memory. See http://bugs.python.org/issue10109

    Author: Fernando Sumudu
    with small changes
    """
    import itertools
    inf_iters = tuple(itertools.cycle(enumerate(it)) for it in iters)
    num_iters = len(inf_iters)
    cur_val = [None]*num_iters

    first_v = True
    while True:
        i, p = 0, num_iters
        while p and not i:
            p -= 1
            i, cur_val[p] = next(inf_iters[p])

        if not p and not i:
            if first_v:
                first_v = False
            else:
                break

        yield cur_val
def _product ( * iters ) : import itertools inf_iters = tuple ( itertools . cycle ( enumerate ( it ) ) for it in iters ) num_iters = len ( inf_iters ) cur_val = [ None ] * num_iters first_v = True while True : i , p = 0 , num_iters while p and not i : p -= 1 i , cur_val [ p ] = next ( inf_iters [ p ] ) if not p and not i : if first_v : first_v = False else : break yield cur_val