human
Rearrange an array such that ' arr [ j ] ' becomes ' i ' if ' arr [ i ] ' is ' j ' | Set 1 | A simple method to rearrange arr [ 0. . n - 1 ] ' ▁ so ▁ that ▁ ' arr [ j ] ' ▁ becomes ▁ ' i ' ▁ if ▁ ' arr [ i ] ' ▁ is ▁ ' j.
Retrieving old value and storing with the new one.
Retrieving new value.
A utility function to pr contents of arr [ 0. . n - 1 ].
Driver code"
How can the above be solved in Python?
assistant
#Here is code to rearrange an array such that ' arr [ j ] ' becomes ' i ' if ' arr [ i ] ' is ' j ' and the other steps required.
 def rearrange ( arr , n ) :
	for i in range ( n ) :
		arr [ arr [ i ] % n ] += i * n
	for i in range ( n ) :
		arr [ i ] //= n
def prArray ( arr , n ) :
	for i in range ( n ) :
		print ( arr [ i ] , end = " ▁ " )
	print ( )
arr = [ 2 , 0 , 1 , 4 , 5 , 3 ]
n = len ( arr )
print ( " Given ▁ array ▁ is ▁ : ▁ " )
prArray ( arr , n )
rearrange ( arr , n )
print ( " Modified ▁ array ▁ is ▁ : " )
prArray ( arr , n )