简体   繁体   中英

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?

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']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM