I have a string "ABChi hi" and I would like to write a program to determine the number of times the substring "hi" occurs in the main string. So far, my code looks like this:
the_word = "ABChi hi"
new_word = the_word.split()
count = 0
for i in new_word:
if i == "hi":
count += 1
The problem is that when I split the string, I get
["ABChi", "hi"]
which will only help me count one of the two hi's that occur, although the correct answer is 2. Does anyone have any ideas on how to obtain the correct answer?