0%
总忘,每次用到都要搜,记录一下
1 2 3 4 5 6 7 8 9 10 11
| from functools import cmp_to_key
score = [97, 80, 90, 63, 72, 84] idx = range(len(score))
idx = sorted(idx, key=cmp_to_key(lambda i, j: score[i]-score[j])) print(idx) sorted_score = [score[i] for i in idx] assert(sorted_score==sorted(score)) print(sorted_score)
|