human
Check if an array has a majority element | Returns true if there is a majority element in a [ ].
Insert all elements in a hash table.
Check if frequency of any element is n / 2 or more ..
Driver code"
How can the above be solved in Python?
assistant
#Here is code to check if an array has a majority element and the other steps required.
 def isMajority ( a ) :
	mp = { }
	for i in a :
		if i in mp : mp [ i ] += 1
		else : mp [ i ] = 1
	for x in mp :
		if mp [ x ] >= len ( a ) // 2 :
			return True
	return False
a = [ 2 , 3 , 9 , 2 , 2 ]
print ( " Yes " if isMajority ( a ) else " No " )