Say I have string = \'hannahannahskdjhannahannah\' and I want to count the number of times the string hannah occurs, I can\'t simply use count, bec
string = \'hannahannahskdjhannahannah\'
hannah
''' s: main string sub: sub-string count: number of sub-strings found p: use the found sub-string's index in p for finding the next occurrence of next sub-string ''' count=0 p=0 for letter in s: p=s.find(sub,p) if(p!=-1): count+=1 p+=1 print count