human
What is a code to check if an array contains only one distinct element and the other steps required given the following:
Check if an array contains only one distinct element | Function to find if the array contains only one distinct element.
Assume first element to be the unique element.
Traversing the array.
If current element is not equal to X then break the loop and print No.
Compare and print the result.
Driver Code.
Function call"
How can the above be solved in Python?
assistant
#Here is code to check if an array contains only one distinct element and the other steps required.
 def uniqueElement ( arr ) :
	x = arr [ 0 ]
	flag = 1
	for i in range ( len ( arr ) ) :
		if ( arr [ i ] != x ) :
			flag = 0
			break
	if ( flag == 1 ) :
		print ( " Yes " )
	else :
		print ( " No " )
arr = [ 9 , 9 , 9 , 9 , 9 , 9 , 9 ]
uniqueElement ( arr )