Look into the 'continue' and 'break' statements - both very handy when working with loops
Or just increment/decrement the conditional until it evaluates to False Bodsda Sent from my BlackBerry® wireless device -----Original Message----- From: lina <[email protected]> Sender: [email protected] Date: Sat, 12 Nov 2011 00:41:43 To: tutor<[email protected]> Subject: [Tutor] how can I save it from "for" 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 - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
