Menu

[Solved]Write Function Python Counts Many Non Overlapping Occurences Substring Appear String Tried Q37154960

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

Expert Answer


Answer to Write a function with Python that counts how many non-overlapping occurences of a substring appear in a string. I tried … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *