Skip to content

Instantly share code, notes, and snippets.

@GeorgeSeif
Created December 28, 2019 16:10
Show Gist options
  • Save GeorgeSeif/0ee1744c0d952ae164f8dd28e1ca5715 to your computer and use it in GitHub Desktop.
Save GeorgeSeif/0ee1744c0d952ae164f8dd28e1ca5715 to your computer and use it in GitHub Desktop.
import nltk
from nltk.corpus import stopwords
sentence = "This is a sentence for removing stop words"
tokens = nltk.word_tokenize(sentence)
stop_words = stopwords.words('english')
filtered_tokens = [w for w in tokens if w not in stop_words]
print(filtered_tokens)
# Prints out ['This', 'sentence', 'removing', 'stop', 'words']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment