human
Convert an array to reduced form | Set 1 ( Simple and Hashing ) | Python3 program to convert an array in reduced form.
Create a temp array and copy contents of arr [ ] to temp.
Sort temp array.
create a map.
One by one insert elements of sorted temp [ ] and assign them values from 0 to n - 1.
Convert array by taking positions from umap.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to convert an array to reduced form and the other steps required.
 def convert ( arr , n ) :
	temp = [ arr [ i ] for i in range ( n ) ]
	temp . sort ( )
	umap = { }
	val = 0
	for i in range ( n ) :
		umap [ temp [ i ] ] = val
		val += 1
	for i in range ( n ) :
		arr [ i ] = umap [ arr [ i ] ]
def printArr ( arr , n ) :
	for i in range ( n ) :
		print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
	arr = [ 10 , 20 , 15 , 12 , 11 , 50 ]
	n = len ( arr )
	print ( " Given ▁ Array ▁ is ▁ " )
	printArr ( arr , n )
	convert ( arr , n )
	print ( " Converted Array is   " )
	printArr ( arr , n )