Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 向nltk.corpus.stopwords.words(';english';)列表追加额外的stopwords或将其作为集合更新将返回非类型对象_Python_Python 3.x - Fatal编程技术网

Python 向nltk.corpus.stopwords.words(';english';)列表追加额外的stopwords或将其作为集合更新将返回非类型对象

Python 向nltk.corpus.stopwords.words(';english';)列表追加额外的stopwords或将其作为集合更新将返回非类型对象,python,python-3.x,Python,Python 3.x,我尝试将nltk中的stopwords追加到其中(作为列表和集合)。但是,它返回一个非类型对象。我采用了以下方法: 扩展列表: stopword=列表(stopwords.words('english')) stopword=stopword.extend(['maggi','maggie','#maggi','#maggie'])) 打印(停止字) 没有 更新集合 stopword=set(stopwords.words('english')) stopword=stopword.updat

我尝试将nltk中的stopwords追加到其中(作为列表和集合)。但是,它返回一个非类型对象。我采用了以下方法:

  • 扩展列表:

    stopword=列表(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')已经是一个列表,因此您无需再次转换为该列表。 在使用list.extend()的地方,我们可以创建另一个列表并将其添加到stopword中,该列表不提供任何类型的输出。 下面的代码将完成任务并获得输出

    from nltk.corpus import stopwords
    stopword = list(stopwords.words('english'))
    l = ['maggi','maggie','#maggi','#maggie']
    stopword = stopword + l
    print(stopword)
    

    我添加了
    list
    命令只是为了更好地衡量,因为上面的方法不起作用
    stopword=stopword.extend('maggi','maggie','#maggi','#maggie'))
    仍将
    None
    (扩展函数返回的结果)分配给
    stopword
    我的坏。。。因此,在使用list.extend()的地方,我们可以创建另一个列表并将其添加到stopword中,该列表不提供任何类型的输出。我已相应地编辑了我的答案。