In [1]:
from nltk.tokenize import sent_tokenize, word_tokenize
from nltk.corpus import stopwords
stop_words = set(stopwords.words("english"))
print(stop_words)


{'s', 'should', 'you', 'she', 'than', 'about', 'this', 'while', 'with', 'and', 'will', 'was', 'yourselves', 'doing', 'myself', 'on', 'been', 'ours', 'our', 'hers', 'now', 'any', 'out', 'its', 'themselves', 'after', 'yours', 'if', 'i', 'how', 'to', 'such', 'again', 'be', 'of', 'don', 'above', 'but', 'not', 'few', 'from', 'it', 'off', 'have', 'an', 'theirs', 'yourself', 'which', 'over', 'am', 'during', 'once', 'these', 'through', 'being', 'against', 'more', 'into', 'some', 'up', 'when', 'there', 'my', 'each', 'your', 'those', 'for', 'we', 'them', 'as', 'between', 'his', 'did', 'do', 'too', 'having', 'they', 'most', 'all', 'same', 'whom', 'their', 'ourselves', 'a', 'or', 'is', 'were', 'nor', 'no', 'then', 'what', 'herself', 'had', 'just', 'me', 'why', 'her', 'further', 'that', 'by', 'in', 'very', 'below', 'does', 'under', 'here', 'him', 'at', 't', 'down', 'the', 'himself', 'other', 'can', 'because', 'own', 'who', 'itself', 'he', 'are', 'both', 'so', 'before', 'until', 'where', 'only', 'has'}

In [2]:
example_sent = "This is a sample sentence, showing off the stop words filtration."
example_words = word_tokenize(example_sent)
print(example_words)


['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.']

We will now remove the stopwords from example_words


In [3]:
tokenized_words = []
for w in example_words:
    if w not in stop_words:
        tokenized_words.append(w)
print(tokenized_words)


['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']