数组的压缩初始化?

时间:2019-03-02 00:15:37

标签: python

我有以下算法,并且想要初始化“ weight”数组,如下所示:

def stredit(s1, s2, w_i=1, w_s=1, w_d=1):
  len1=len(s1)
  len2=len(s2)
  table=[[(0,'')]*(len1+1) for i in range(len2+1)]
  # some code
  char = 'c'
  weight=[(table[i-1][j-1]+d,char), (table[i-1][j]+w_i, 'i'), (table[i][j-1]+w_d, 'd')].sort()
  table[i][j]=weight[0]
return table[len1][len2]

但这会引发以下错误:'NoneType' object is not subscriptable。调试时,我意识到初始化后权重为None类型。

0 个答案:

没有答案
相关问题