human
Reorder an array according to given indexes | Function to reorder elements of arr [ ] according to index [ ].
Fix all elements one by one.
While index [ i ] and arr [ i ] are not fixed.
Store values of the target ( or correct ) position before placing arr [ i ] there.
Place arr [ i ] at its target ( or correct ) position . Also copy corrected index for new position.
Copy old target values to arr [ i ] and index [ i ].
Driver program"
How can the above be solved in Python?
assistant
#Here is code to reorder an array according to given indexes and the other steps required.
 def reorder ( arr , index , n ) :
	for i in range ( 0 , n ) :
		while ( index [ i ] != i ) :
			oldTargetI = index [ index [ i ] ]
			oldTargetE = arr [ index [ i ] ]
			arr [ index [ i ] ] = arr [ i ]
			index [ index [ i ] ] = index [ i ]
			index [ i ] = oldTargetI
			arr [ i ] = oldTargetE
arr = [ 50 , 40 , 70 , 60 , 90 ]
index = [ 3 , 0 , 4 , 1 , 2 ]
n = len ( arr )
reorder ( arr , index , n )
print ( " Reordered ▁ array ▁ is : " )
for i in range ( 0 , n ) :
	print ( arr [ i ] , end = " ▁ " )
print ( " Modified Index array is : " )
for i in range ( 0 , n ) :
	print ( index [ i ] , end = " ▁ " )