human
Give me a code to count pairs of equal elements possible by excluding each array element once and the other steps required given the following:
Count pairs of equal elements possible by excluding each array element once | Function to count the number of required pairs for every array element.
Initialize a map.
Update the frequency of every element.
Stores the count of pairs.
Traverse the map.
Count the number of ways to select pairs consisting of equal elements only.
Traverse the array.
Print the count for every array element.
Driver code.
Given array.
Size of the array"
How can the above be solved in Python?
assistant
#Here is code to count pairs of equal elements possible by excluding each array element once and the other steps required.
 def countEqualElementPairs ( arr , N ) :
	mp = { }
	for i in range ( N ) :
		if arr [ i ] in mp :
			mp [ arr [ i ] ] += 1
		else :
			mp [ arr [ i ] ] = 1
	total = 0
	for key , value in mp . items ( ) :
		total += ( value * ( value - 1 ) ) / 2
	for i in range ( N ) :
		print ( int ( total - ( mp [ arr [ i ] ] - 1 ) ) , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 1 , 2 , 1 , 2 ]
	N = len ( arr )
	countEqualElementPairs ( arr , N )