Python:不可散列的类型:NLTK的“列表”

时间:2018-07-27 16:03:25

标签: python python-3.x

我正在尝试使用NLTK库传递复数形式的英语单词列表。我对这些概念有些陌生。我的书写方式无法将单词列表传递到Lem.lemmatize(words)中,因为我可以传递单个words ='ants'。我究竟做错了什么?我看到了类似的问题,但不清楚为什么它不接受列表格式?

from nltk.stem.wordnet import WordNetLemmatizer
Lem = WordNetLemmatizer()
#words = [] 
words = ['ants', 'WOMEN', 'boys', 'needs', 'FINDS', 'binaries', 'HOBBIES', 'busses', 'wolves']
[w for w in words if w.lower() in Lem.lemmatize(words)] # 

output: 
['ant','woman','boy','need','find','binary','hobby','bus','wolf']

1 个答案:

答案 0 :(得分:0)

因为内部处理要求输入参数(作为一个整体)作为一个可哈希的项以进行适当的检查,并保证在使用结果时不变。因此,该词典必须是可哈希的类型; “可哈希”是“不可变”的子集。

尝试将其转换为元组。

相关问题