简体   繁体   中英

Trouble putting lemmatized words into a list

So I am working with a lemmatizer in Python, pystempel to be exact. And I am trying to lemmatize words in a text file and write the values all down in a list, so I can do some further work with the lemmatized list. However, I can't get the lemmatizer to actually change the value of these words.

import string
from stempel import StempelStemmer

stemmer = StempelStemmer.polimorf()

for word in *text file*:
 (stemmer.stem(word))

Something like this doesen't work because I think it just lemmatizes the words and does nothing else. Can someone help out and tell me how I could lemmatize each word from the text file and put them into a list that I can use later on?

Strings are an immutable datatype, you cannot change their value. Your lemmatizer is probably returning a value that is the new string that has been lemmatized. You should probably take each lemmatized value and append it to a list. Example:

lemmatized = []
for word in text file: 
  lemmatized.append(stemmer.stem(word))

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