def getsortfunction(values, indices):
    sorts = [sorted(list(set(x[indices[i][0]] for x in values)), reverse=
        indices[i][1]) for i in range(len(indices))]

def sortfunction(y):
    return tuple(sorts[i].index(y[indices[i][0]]) for i in range(len(indices)))
return sortfunction
Сортировка на разных уровнях в Python