human
Write me a the Python program you requested given the following:
Complete the below
def _sorted_factors(factors, method):

    ''''Sort a list of ``(expr, exp)`` pairs.'
    '''
assistant
#Here is the Python program you requested.
    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)