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
例如...在我的word_list中...我有“爱不会让世界变得圆润。爱是让这次旅行变得有价值的事情”
我想打印出不是停止词的所有单词......
但它只打印出爱,制造,去,圆,爱,制造,值得.......单词“世界,骑”不打印出来。任何人都知道如何解决它?谢谢......
答案 0 :(得分:1)
如果您更改word_list
,那么这是一个单词列表,它可以正常工作。 word_list
将包含您所追求的字词。
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']