human
Give me a code to print all pairs with given sum and the other steps required given the following:
Print all pairs with given sum | Returns number of pairs in arr [ 0. . n - 1 ] with sum equal to sum.
Store counts of all elements in a dictionary.
Traverse through all the elements.
Search if a pair can be formed with arr [ i ].
Driver code"
Solution in Python:
assistant
#Here is code to print all pairs with given sum and the other steps required.
 def printPairs ( arr , n , sum ) :
	mydict = dict ( )
	for i in range ( n ) :
		temp = sum - arr [ i ]
		if temp in mydict :
			count = mydict [ temp ]
			for j in range ( count ) :
				print ( " ( " , temp , " , ▁ " , arr [ i ] , " ) " , sep = " " , end =   ' ' )
		if arr [ i ] in mydict :
			mydict [ arr [ i ] ] += 1
		else :
			mydict [ arr [ i ] ] = 1
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 5 , 7 , - 1 , 5 ]
	n = len ( arr )
	sum = 6
	printPairs ( arr , n , sum )