Converting plural to singular in a text file with Python
问题 I have txt files that look like this: word, 23 Words, 2 test, 1 tests, 4 And I want them to look like this: word, 23 word, 2 test, 1 test, 4 I want to be able to take a txt file in Python and convert plural words to singular. Here's my code: import nltk f = raw_input("Please enter a filename: ") def openfile(f): with open(f,'r') as a: a = a.read() a = a.lower() return a def stem(a): p = nltk.PorterStemmer() [p.stem(word) for word in a] return a def returnfile(f, a): with open(f,'w') as d: d =