Search code examples
pythonpython-2.7stop-words

Why are the stop words not updating even after adding stop words to the english.txt file?


I am using stop_words package in Python. The original number of stop words in the english.txt file in the directory path usr/local/lib/python2.7/dist-packages/stop_words/stop-words was 174 and I added a few more and the list became 218.

I use the following commands to get the stop words

from stop_words import get_stop_words

en_stop = get_stop_words('en')

len(en_stop) still shows 174. Please can you tell me how to make the changes reflect?


Solution

  • You shouldn't add stop words to the file. To add stop words you should create a list of words you want to add and then use the union function of set to create a new list.

    en_stop = set(get_stop_words('en'))
    new_stop = {'newstopword'}
    en_stop = en_stop.union(new_stop)