繁体   English   中英

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

[英]Python: unhashable type: 'list' for NLTK

我正在尝试使用NLTK库传递复数形式的英语单词列表。 我对这些概念有些陌生。 我的写作方式无法将单词列表传递给Lem.lemmatize(words) ,因为我可以传递单个words ='ants' 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']

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

尝试将其转换为元组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM