human
Sort array after converting elements to their squares | Function to sort an square array.
First convert each array elements into its square.
Sort an array using " inbuild ▁ sort ▁ function " in Arrays class.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to sort array after converting elements to their squares and the other steps required.
 def sortSquare ( arr , n ) :
	for i in range ( n ) :
		arr [ i ] = arr [ i ] * arr [ i ]
	arr . sort ( )
arr = [ - 6 , - 3 , - 1 , 2 , 4 , 5 ]
n = len ( arr )
print ( " Before ▁ sort " )
for i in range ( n ) :
	print ( arr [ i ] , end = " ▁ " )
print ( " " )
sortSquare ( arr , n )
print ( " After ▁ sort " )
for i in range ( n ) :
	print ( arr [ i ] , end = " ▁ " )