将其他停用词附加到 nltk.corpus.stopwords.words('english') 列表或更新为集合返回 NoneType 对象



我尝试从 nltk 附加到停用词(作为列表和设置(。但是,它返回一个 NoneType 对象。我使用了以下方法:

  1. 扩展列表:

    停用词 = list(停用词.words('English'((

    停用词 = 停用词.extend(['Maggi','Maggie','#maggi','#maggie'](

    打印(停用词(

    没有

  2. 更新集

    停用词 = set(停用词.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)

最新更新