python-3.x - 比较列表时不可散列
问题描述
我不熟悉我在这里收到的不可散列的错误。我有以下数据框'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)
解决方案
问题解决了。列表没有展平,所以我通过这个而不是每个单独的项目运行列表列表
推荐阅读
- mongodb - MongoClient() 对象返回 500 内部错误而不是空白页
- axios - Branchio 返回相同的深层链接
- c# - 如果我仍然使用 TaskCompletionSource 来实现异步,我应该返回 ValueTask 吗?
- java - 如何在 Junit 5 中动态传递多个输入和输出测试文件名?
- vue.js - 使用 vue 更改动态创建的按钮上的文本
- c++ - C++ 使用另一个类中的对象
- ios - 如何快速获得字符串中的第一个元音
- android-studio - 如何收听 admob 插页式印象?
- spring - Spring Test Junit 5 & Security boot 2.2 如何模拟身份验证?
- python - python类变量和实例变量