human
Can you provide a code to count of greater elements for each element in the Array and the other steps required given the following:
Count of greater elements for each element in the Array | Python 3 implementation of the above approach.
Store the frequency of the array elements.
Store the sum of frequency of elements greater than the current element.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to count of greater elements for each element in the Array and the other steps required.
 def countOfGreaterElements ( arr , n ) :
	mp = { i : 0 for i in range ( 1000 ) }
	for i in range ( n ) :
		mp [ arr [ i ] ] += 1
	x = 0
	p = [ ]
	q = [ ]
	m = [ ]
	for key , value in mp . items ( ) :
		m . append ( [ key , value ] )
	m = m [ : : - 1 ]
	for p in m :
		temp = p [ 1 ]
		mp [ p [ 0 ] ] = x
		x += temp
	for i in range ( n ) :
		print ( mp [ arr [ i ] ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 7 , 9 , 5 , 2 , 1 , 3 , 4 , 8 , 6 ]
	n = len ( arr )
	countOfGreaterElements ( arr , n )