使用Python在不改变原数组顺序的情况下添加数组数据元素的排名(从小到大)

aa = [33.46, 73.51, 28.38, 32.95, 74.74, 21.95, 27.34, 
        36.65, 12.23, 44.11, 20.54, 32.94, 21.51, 26.14, 15.29]
bb = [(aa[i-1], i) for i in range(1, len(aa) + 1)]
cc = sorted(bb)
dd = [(cc[i-1][0], i, cc[i-1][1]) for i in range(1, 16)]
ee = sorted(dd, key=lambda x: x[2])
ff = [(x[0], x[1]) for x in ee]
print(ff)
"D:\Program Files\Python36\python3.exe" D:/MyProject/Python/ReturnVisit/test.py
[(33.46, 11), (73.51, 14), (28.38, 8), (32.95, 10), (74.74, 15), (21.95, 5), (27.34, 7), 
(36.65, 12), (12.23, 1), (44.11, 13), (20.54, 3), (32.94, 9), (21.51, 4), (26.14, 6), (15.29, 2)]

Process finished with exit code 0

猜你喜欢

转载自blog.csdn.net/TomorrowAndTuture/article/details/103618374