I have two lists and fancy to sort them according to the first one. I get indexes how the first array s was sorted. How to apply the same order/the list of indexes to the s2, please?
s = [2, 3, 1, 4, 5, 3]
sorted(range(len(s)), key=lambda k: s[k])
>>[2, 0, 1, 5, 3, 4]
s1 = [20, 30, 10, 40, 50, 3
0]
CodePudding user response:
this shoud work
res = []
for i in range(len(s1)):
res[i] = s1[s[i]]