0

我收到此错误:

发生了这样的错误“在赋值之前引用了局部变量'words'”

我该如何解决?这是我的代码:

def bag_of_words(sentence):
    sentence_words = clean_up_sentence(sentence)
    bag = [0] * len(words) 
    for w in sentence_words:
        for i, words in enumerate(words):
            if word == w:
                bag[i] = 1
    return np.array(bag) 
4

1 回答 1

1

在这一行:

bag = [0] * len(words) 

您正在使用该变量words,但它在此上下文中不存在

于 2021-03-03T08:59:15.347 回答