human
Can you provide a code to print all the pairs that contains the positive and negative values of an element and the other steps required given the following:
Print all the pairs that contains the positive and negative values of an element | Function to print pairs of positive and negative values present in the array.
Store all the positive elements in the unordered_set.
Start traversing the array.
Check if the positive value of current element exists in the set or not.
Print that pair.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to print all the pairs that contains the positive and negative values of an element and the other steps required.
 def printPairs ( arr , n ) :
	pairs = set ( )
	pair_exists = False
	for i in range ( 0 , n ) :
		if arr [ i ] > 0 :
			pairs . add ( arr [ i ] )
	for i in range ( 0 , n ) :
		if arr [ i ] < 0 :
			if ( - arr [ i ] ) in pairs :
				print ( " { } , ▁ { } " . format ( arr [ i ] , - arr [ i ] ) )
				pair_exists = True
	if pair_exists == False :
		print ( " No ▁ such ▁ pair ▁ exists " )
if __name__ == " _ _ main _ _ " :
	arr = [ 4 , 8 , 9 , - 4 , 1 , - 1 , - 8 , - 9 ]
	n = len ( arr )
	printPairs ( arr , n )