Reputation: 1693
word_list = "love does not make the world go round. love is what makes the ride worthwhile"
from nltk.corpus import stopwords
for word in word_list:
#print word
if word in stopwords.words('english'):
#print word #print out stopword for checking
word_list.remove(word)
else:
print word
for example...In my word_list...I have "love does not make the world go round. love is what makes the ride worthwhile"
I want to print out all word that not in stop word...
but it print out only love, make, go, round, love, makes, worthwhile.......Word "world, ride" is not print out..Anyone know how to solve it? Thank you...
Upvotes: 1
Views: 115
Reputation: 35299
If you change word_list
, so that it is a list of words, it works fine. word_list
will contain the words you are after.
word_list = ['love','does','not','make','the','world','go','round','love',
'is','what','makes','the','ride','worthwhile']
#your code:
from nltk.corpus import stopwords
for word in word_list:
#print word
if word in stopwords.words('english'):
#print word #print out stopword for checking
word_list.remove(word)
else:
print word
#now put:
print word_list
#output:
['love', 'not', 'make', 'world', 'go', 'round', 'love', 'what',
'makes', 'ride', 'worthwhile']
Upvotes: 1