Dinesh Kr Malav
Dinesh Kr Malav

Reputation: 1

while performing stopwords on dataset in python3 getting error in printing function

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

Answers (1)

dimid
dimid

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

Related Questions