Re: [Tutor] how can I save it from "for"

2011-11-11 Thread bodsda
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 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Sat, 12 Nov 2011 00:41:43 
To: tutor
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  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how can I save it from "for"

2011-11-11 Thread lina
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