def _sorted_factors(factors, method):
 if (method == 'sqf'):
  def key(obj):
   (poly, exp) = obj
   rep = poly.rep.rep
   return (exp, len(rep), len(poly.gens), rep)
 else:
  def key(obj):
   (poly, exp) = obj
   rep = poly.rep.rep
   return (len(rep), len(poly.gens), exp, rep)
 return sorted(factors, key=key)

def _sorted_factors ( factors , method ) : if ( method == 'sqf' ) : def key ( obj ) : ( poly , exp ) = obj rep = poly . rep . rep return ( exp , len ( rep ) , len ( poly . gens ) , rep ) else : def key ( obj ) : ( poly , exp ) = obj rep = poly . rep . rep return ( len ( rep ) , len ( poly . gens ) , exp , rep ) return sorted ( factors , key = key )
sort a list of pairs .