Hi, I don't know how to escape the

        if longest >= 3:
            subgroup=S1[x_longest-longest:x_longest]
            print(subgroup)

form the loop.


xrange = range

subgroup=[]
def LongestCommonSubstring(S1, S2):
    M = [[0]*(1+len(S2)) for i in xrange(1+len(S1))]
    longest, x_longest = 0, 0
    subgroups=[]
    uniq={}
    for x in xrange(1,1+len(S1)):
        for y in xrange(1,1+len(S2)):
            if S1[x-1] == S2[y-1]:
                M[x][y] = M[x-1][y-1]+1
                if M[x][y] > longest:
                    longest = M[x][y]
                    x_longest = x
            else:
                    M[x][y] = 0
        if longest >= 3:
            subgroup=S1[x_longest-longest:x_longest]
            print(subgroup)


    return S1[x_longest-longest:x_longest]


if __name__=="__main__":

    for i in range(97,107):
        for j in range(97,107):
            if i != j:
                LongestCommonSubstring(a,b)
                '''LongestCommonSubstring(chr(i),chr(j))'''

Thanks ahead,
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to