human
Count occurrences of a word in string | Python program to count the number of occurrence of a word in the given string.
split the string by spaces in a.
search for pattern in a.
if match found increase count.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to count occurrences of a word in string and the other steps required.
 def countOccurrences ( str , word ) :
	a = str . split ( " ▁ " )
	count = 0
	for i in range ( 0 , len ( a ) ) :
		if ( word == a [ i ] ) :
		count = count + 1
	return count
str = " GeeksforGeeks ▁ A ▁ computer ▁ science ▁ portal ▁ for ▁ geeks ▁ "
word = " portal "
print ( countOccurrences ( str , word ) )