In my code I try to found index of the pattern, count every comparison and I also want to stop this algorithm then my pattern is too long for comparison to rest of the text. Something is wrong with counter and I couldn't stop algorithm. I am beginner and I don't have idea what to do.
def search(W, T):
count = 0
for i in range(len(T) - len(W) + 1):
if i > len(T)-len(W):
break
j = 0
while(j < len(W)):
if (T[i + j] != W[j]):
count += 1
break
j += 1
if (j == len(W)):
count += len(W)
print("Pattern found at index ", i, count)
if __name__ == '__main__':
T = "AABAACAADAABAAABAA"
W = "AABA"
search(W, T)
Thanks for helping.
I expect that someone will change my code or tell me what to do.