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:
-
Extending a list:
stopword = list(stopwords.words(‘english’))
stopword = stopword.extend([‘maggi’,’maggie’,’#maggi’,’#maggie’])
print(stopword)
None
-
Updating a set
stopword = set(stopwords.words(‘english’))
stopword = stopword.update(set([‘maggi’,’maggie’,’#maggi’,’#maggie’]))
print(stopword)
None
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)
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:
-
Extending a list:
stopword = list(stopwords.words(‘english’))
stopword = stopword.extend([‘maggi’,’maggie’,’#maggi’,’#maggie’])
print(stopword)
None
-
Updating a set
stopword = set(stopwords.words(‘english’))
stopword = stopword.update(set([‘maggi’,’maggie’,’#maggi’,’#maggie’]))
print(stopword)
None
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)