Write a function with Python that counts how manynon-overlapping occurences of a substring appear in a string.
I tried but it fails all tests except for one:
def count(substr,theStr):
count = start = 0
while True:
start = substr.find(theStr, start) + 1
if start < 0:
count+=1
else:
return count
Solution
def countSubStr(substr,theStr): count = 0 while True: start = theStr.find(substr) + 1 theStr = theStr[start+len(substr):] if start > 0: count+=1
OR
OR