我在定义模块时遇到了这个错误。我试图用动态规划的方法编写一个编辑距离问题的程序。在
以下是我遇到的模块:
def cost(i,j,M,w,text,pattern,compare): #Defining the cost functions or can say recurrence formula
M[0,j]=0
text1=list(text)
pattern1=list(pattern)
for i in range(1,m+1):
for j in range(1,n+1):
insertions = M[i-1,j]+1
deletions = M[i,j-1]+1
matches=M[i-1,j-1]
if text1[i]==patttern1[j]:
matches = matches+1
return matches
else :
return matches
错误是:
Traceback (most recent call last): File "/Users/sayaneshome/Documents/plschk.py", line 202, in fill(M, w, text, max) #Filling matrix M with scores File "/Users/sayaneshome/Documents/plschk.py", line 117, in fill c = cost(i,j,M,w,text,pattern,compare) File "/Users/sayaneshome/Documents/plschk.py", line 95, in cost if text1[i]==patttern1[j]: NameError: global name 'patttern1' is not defined
您的}。在
patttern1
有三个t
。删除一个可以得到{相关问题 更多 >
编程相关推荐