Reputation: 1
I'm trying to remove stop words using NLTK
. I have a syntax error in the fourth line, but the first three lines are working fine.
File "<stdin>", line 1
print [i for i in senten
^
SyntaxError: invalid syntax
My code:
from nltk.corpus import stopwords
stop = stopwords.words('english')
sentence = "this is a foo bar sentence"
print [i for i in sentence.split() if i not in stop]
Upvotes: 0
Views: 663
Reputation: 7649
In python3 it's probably due to missing parenthesis in print
, i.e.
print([i for i in sentence.split() if i not in stop])
Upvotes: 1