human
Rearrange array by interchanging positions of even and odd elements in the given array | Function to replace each even element by odd and vice - versa in a given array.
Traverse array.
If current element is even then swap it with odd.
Perform Swap.
Change the sign.
If current element is odd then swap it with even.
Perform Swap.
Change the sign.
Marked element positive.
Print final array.
Driver Code.
Given array arr [ ].
Function Call"
How can the above be solved in Python?

Give me a code to rearrange array by interchanging positions of even and odd elements in the given array and the other steps required?
assistant
#Here is code to rearrange array by interchanging positions of even and odd elements in the given array and the other steps required.
 def replace ( arr , n ) :
	for i in range ( n ) :
		for j in range ( i + 1 , n ) :
			if ( arr [ i ] >= 0 and arr [ j ] >= 0 and arr [ i ] % 2 == 0 and arr [ j ] % 2 != 0 ) :
				tmp = arr [ i ]
				arr [ i ] = arr [ j ]
				arr [ j ] = tmp
				arr [ j ] = - arr [ j ]
				break
			elif ( arr [ i ] >= 0 and arr [ j ] >= 0 and arr [ i ] % 2 != 0 and arr [ j ] % 2 == 0 ) :
				tmp = arr [ i ]
				arr [ i ] = arr [ j ]
				arr [ j ] = tmp
				arr [ j ] = - arr [ j ]
				break
	for i in range ( n ) :
		arr [ i ] = abs ( arr [ i ] )
	for i in range ( n ) :
		print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 3 , 2 , 4 ]
	n = len ( arr )
	replace ( arr , n )