given
a = [1,4,5,3,2,6,0]
b = ['b','e','f','d','c','g','a']
order b
in place, the expected order of b
is available in the corresponding positional element of a
.
output will be
['a','b','c','d','e','f','g']
try for other similar input sets.
a = [4,0,1,3,2]
b = ['E','A','B','D','C']
I can get it done using a third list, even sorted()
creates a third list, but the key is to sort b
in place
print sorted(b,key=lambda bi : a[b.index(bi)])
core of the problem is how to prevent iterating over items in b
that were already iterated.