1
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には...「愛は世界を一周させるものではありません。愛は乗り心地を価値あるものにするものです」

ストップワード以外のすべての単語を印刷したい...

しかし、それは愛、作る、行く、丸める、愛する、作る、価値があるだけを印刷します.......「世界、乗る」という言葉は印刷されません..誰もがそれを解決する方法を知っていますか?ありがとうございました...

4

1 に答える 1

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']
于 2012-04-16T19:11:31.117 に答える