Ok so here's my problem, I defined a function that's suppose to count the number of times a certain fragment occurs in a string. The function starts searching at Index[0] and subsequent searches start at the index of the last match in the string.
HERE'S THE CODE
def function(fragment, string):
count = -1
last_match = 0
while last_match != -1:
count += 1
last_match = string.find(fragment, last_match)
return count
Now here's the problem, When pass the parameters to the function with a fragment that's obviously a match in the string I get an infinite loop. When I fix the infinite loop, If a pass fragment that located in Index[0] the function doesn't return a the right count???
ex:
function('gtg' , 'gttacgtggatg' ) This gives me an infinite loop
function('gtt' , 'gttacgtggatg' ) This doesn't return a count..
Just looking for some help and input..
Thanks