Keithx
Keithx

Reputation: 3148

Stemming words in a Python list

Have a list "l" with distinct words like this:

'gone',
'done',
'crawled',
'laughed',
'cried'

I try to apply stemming on this list just that way:

from stemming.porter2 import stem
l = [[stem(word) for word in sentence.split(' ')] for sentence in l]

But nothing seems to happen and nothing changes. What am I doing wrong with the stemming procedure?

Upvotes: 0

Views: 1502

Answers (1)

Néstor
Néstor

Reputation: 351

Your code has one mistake. l is a list of words, not sentences. You have to do this:

l = [stem(word) for word in l]

For example:

>>> l = ['gone', 'done', 'crawled', 'laughed', 'cried']
>>> [stem(word) for word in l]
['gone', 'done', 'crawl', 'laugh', 'cri']

Upvotes: 1

Related Questions