In the end of function LCSlist(i,j)
, it should return ['a', 't', 't', 'a', 'c', 'g', 'c', 't', 'a']
.But my output is "None".And when I check the type of my output, the class is "NoneType" (<class 'NoneType'>
). Can anyone help?
here is my code:
s1 = 'aatcatacggcatac'
s2 = 'cattaccagactag'
ls1 = len(s1)
ls2 = len(s2)
DP = [[-1 for i in range(ls2+1)] for j in range(ls1+1)]
for i in range(ls1):
DP[i][0] = 0
for j in range(ls2):
DP[0][j] = 0
#print(DP)
track = [[-1 for i in range(ls2+1)] for j in range(ls1+1)]
def LCS(i,j):
#print(DP)
if DP[i][j] != -1:
return DP[i][j]
else:
if(s1[i-1] == s2[j-1]):
track[i-1][j-1] = 3
DP[i][j] = 1 + LCS(i-1,j-1)
else:
r1 = LCS(i-1,j)
r2 = LCS(i,j-1)
DP[i][j] = max(r1 , r2)
if DP[i][j] == r1:
track[i-1][j-1] = 1
else:
track[i-1][j-1] = 2
return DP[i][j]
alist = []
def LCSlist(i,j):
#print(alist)
if (i < 0) | (j < 0):
alist.reverse()
print(alist)
return alist
else:
if track[i][j] == 3:
alist.append(s2[j])
print(alist)
LCSlist(i-1,j-1)
elif track[i][j] == 2:
LCSlist(i,j-1)
else:
LCSlist(i-1,j)
print( "Ans is",LCS(ls1,ls2) )
print( "LCSlist is" ,type(LCSlist(ls1-1,ls2-1)))