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)

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 )
cartesian product generator notes unlike itertools .