pythonlistloopsnltkstemming

Stemming words in a list (Python NLTK)


I feel like I'm doing something really stupid here, I am trying to stem words I have in a list but it is not giving me the intended outcome, my code is:

from nltk.stem.snowball import SnowballStemmer
snowball = SnowballStemmer(language="english")
my_words = ['works', 'shooting', 'runs']
for w in my_words:
    w=snowball.stem(w)
print(my_words)

and the ouput I get is

['works', 'shooting', 'runs]

as opposed to

['work','shoot','run']

I feel like I'm doing something very silly with my list but could anyone enlighten me what I'm doing wrong?


Solution

  • You can use list comprehension :

    [snowball.stem(word) for word in my_words]