def build_product_order(arg, gens):
 gens2idx = {}
 for (i, g) in enumerate(gens):
  gens2idx[g] = i
 order = []
 for expr in arg:
  name = expr[0]
  var = expr[1:]
  def makelambda(var):
   return _ItemGetter((gens2idx[g] for g in var))
  order.append((monomial_key(name), makelambda(var)))
 return ProductOrder(*order)

def build_product_order ( arg , gens ) : gens2idx = { } for ( i , g ) in enumerate ( gens ) : gens2idx [ g ] = i order = [ ] for expr in arg : name = expr [ 0 ] var = expr [ 1 : ] def makelambda ( var ) : return _ItemGetter ( ( gens2idx [ g ] for g in var ) ) order . append ( ( monomial_key ( name ) , makelambda ( var ) ) ) return ProductOrder ( * order )
build a monomial order on gens .