python - 将其他停用词附加到 nltk.corpus.stopwords.words('english') 列表或作为一组更新返回 NoneType 对象
问题描述
我尝试从 nltk 附加到停用词(作为列表和集合)。但是,它返回一个 NoneType 对象。我使用了以下方法:
扩展列表:
stopword = list(stopwords.words('english'))
stopword = stopword.extend(['maggi','maggie','#maggi','#maggie'])
打印(停用词)
没有任何
更新集合
stopword = set(stopwords.words('english'))
stopword = stopword.update(set(['maggi','maggie','#maggi','#maggie']))
打印(停用词)
没有任何
解决方案
stopwords.words('english') 已经是一个列表,因此您无需再次转换为列表。在使用给出 None 类型输出的 list.extend() 的地方,我们可以创建另一个列表并将其添加到停用词中。因此,以下代码将完成任务并为您提供输出
from nltk.corpus import stopwords
stopword = list(stopwords.words('english'))
l = ['maggi','maggie','#maggi','#maggie']
stopword = stopword + l
print(stopword)
推荐阅读
- r - 嵌套循环错误:矩阵上的下标数量不正确
- c++ - 在 std::string::end() 和 std::string::capacity() 之间使用缓冲区
- swift - Type conversion error when reading data from Firebase
- python - Python how do it get pure data from user input in an entry widget=
- javascript - 如何将信息从 div 发送到电报机器人?
- django - 如何在 Django 中进行删除确认
- swiftui - 如何在 SwiftUI 中删除 HStack 上的 TextField 和 Text 之间的空格?
- openapi - what are mandatory elements in OpenAPI spec
- ruby-on-rails - 为什么belongs_to / has_many 和inverse_of 不能自动水合对方?
- python - Can anyone help me with reading a continuously updating video file with python?