human
Give me a code to count number of occurrences ( or frequency ) in a sorted array and the other steps required given the following:
Count number of occurrences ( or frequency ) in a sorted array | Returns number of times x occurs in arr [ 0. . n - 1 ].
Driver code"
How can the above be solved in Python?
assistant
#Here is code to count number of occurrences ( or frequency ) in a sorted array and the other steps required.
 def countOccurrences ( arr , n , x ) :
	res = 0
	for i in range ( n ) :
		if x == arr [ i ] :
			res += 1
	return res
arr = [ 1 , 2 , 2 , 2 , 2 , 3 , 4 , 7 , 8 , 8 ]
n = len ( arr )
x = 2
print ( countOccurrences ( arr , n , x ) )