Appending additional stopwords to nltk.corpus.stopwords.words('english') list or updating as a set returns NoneType object

Question:

I tried appending to the stopwords from nltk (both as list and set). However, it returns a NoneType object. I have used the following approaches:

  1. Extending a list:

    stopword = list(stopwords.words(‘english’))

    stopword = stopword.extend([‘maggi’,’maggie’,’#maggi’,’#maggie’])

    print(stopword)

    None

  2. Updating a set

    stopword = set(stopwords.words(‘english’))

    stopword = stopword.update(set([‘maggi’,’maggie’,’#maggi’,’#maggie’]))

    print(stopword)

    None

Asked By: Parth Batra

||

Answers:

stopwords.words(‘english’) is already a list so you don’t need to convert into the list again.
At the place of using list.extend() which is giving None type output, we can just create another list and add it to stopword.
So following code will complete the task and get you the output

from nltk.corpus import stopwords
stopword = list(stopwords.words('english'))
l = ['maggi','maggie','#maggi','#maggie']
stopword = stopword + l
print(stopword)
Answered By: Anay Dongre
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.