首页 > 解决方案 > 比较列表时不可散列

问题描述

我不熟悉我在这里收到的不可散列的错误。我有以下数据框'dfd',我正在隔离角色描述。从那里,我将角色描述中的每个单词拆分出来,并将整个列表合并到一个列表中。从这个列表中,我尝试将其与将过滤掉混乱的停用词列表进行比较。

此代码在 if 语句处失败: if w not in stop_words: TypeError: unhashable type: 'list'

有人可以解释问题是什么吗?我觉得这应该是直截了当的。

dfd = dfd['Role Description']

mylist =[]
for role in dfd:
    tokenized_word=word_tokenize(role)
    mylist.append(tokenized_word)

stop_words=set(stopwords.words("english"))

map(str, mylist)

print(mylist)

filtered_sent=[]
for w in mylist:
    if w not in stop_words:
        filtered_sent.append(w)
print("Filtered Sentence:",filtered_sent)

标签: python-3.xnltk

解决方案


问题解决了。列表没有展平,所以我通过这个而不是每个单独的项目运行列表列表


推荐阅读