Trying to implement Boyer Moore, bad character matching algorithm without looking at the answers. I want to exit this loop I wrote with just one line of "No match" if there was no pattern found, here is my code:
T = 'ATGGGTATGGCTCGGCTCGG'
p = 'ATCG'
skip = 0
while skip + len(p) < len(T):
    string = T[skip:skip+len(p)]
    if string == p:
        print "offset at: ", skip
        break
    for i in range(len(string), 0, -1):
        if (string[i-1] != p[i-1]):
                if string[i-1] in p[:i-1]:
                    skip += (i - p.find(string[i-1]) - 1)
                    break
                elif not string[i-1] in p[:i-1]:
                    skip += i
                    break
Any hits regarding how to modify the code.
Thank you,
xp
edit: Scheme gave me the answer, as easy as that. I was so looping my head in the line string == p or string != p. Thank you for all your comments.
 
     
    