human
Print numbers in descending order along with their frequencies | Function to print the elements in descending along with their frequencies.
Sorts the element in decreasing order.
traverse the array elements.
Prints the number and count.
Prints the last step.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to print numbers in descending order along with their frequencies and the other steps required.
 def printElements ( a , n ) :
	a . sort ( reverse = True )
	cnt = 1
	for i in range ( n - 1 ) :
		if ( a [ i ] != a [ i + 1 ] ) :
			print ( a [ i ] , " ▁ occurs ▁ " , cnt , " times " )
			cnt = 1
		else :
			cnt += 1
	print ( a [ n - 1 ] , " occurs " , cnt , " times " )
if __name__ == " _ _ main _ _ " :
	a = [ 1 , 1 , 1 , 2 , 3 , 4 , 9 , 9 , 10 ]
	n = len ( a )
	printElements ( a , n )