I have a list containing strings that I am lemmatizing. Though I can lemmatize all the strings, I am having a hard time returning the lemmatized strings in the same list format that I inputted to the lemmatizer.
Doing a type of each of the outputs, I get a unicode and str objects. I tried converting the unicode to strings and tried to concatenate the strings to a list but with no luck.
Below is the reproducible code:
typea = ['colors', 'caresses', 'ponies', 'presumably', 'owed', 'says']
for i in xrange(0,len(typea)):
# Lemmatize the words
lemmatized_words = lmtzr.lemmatize(typea[i])
print lemmatized_words
#Output obtained:
color
caress
pony
presumably
owed
say
#Desired output
#['color', 'caress', 'pony', 'presumably', 'owed', 'say']
lmtzr.lemmatize
takes a single string and returns a single string. So lemmatized_words
will be a single string at a time.
To lemmatize all the words and store them in a list, you want something like this:
typea = ['colors', 'caresses', 'ponies', 'presumably', 'owed', 'says']
lemmatized_words = [lmtzr.lemmatize(x) for x in typea]
print lemmatized_words