我有txt文件,如下所示:
word, 23
Words, 2
test, 1
tests, 4
Run Code Online (Sandbox Code Playgroud)
我希望它们看起来像这样:
word, 23
word, 2
test, 1
test, 4
Run Code Online (Sandbox Code Playgroud)
我希望能够在Python中获取一个txt文件并将多个单词转换为单数.这是我的代码:
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 = d.write(a)
#d.close()
print openfile(f)
print stem(openfile(f))
print returnfile(f, stem(openfile(f)))
Run Code Online (Sandbox Code Playgroud)
我也尝试过这两个定义而不是stem定义:
def singular(a):
for line in …Run Code Online (Sandbox Code Playgroud) 我有一个ubuntu linux,一直在使用这个网站:https://scottlinux.com/2013/10/11/how-to-create-a-tor-onion-site/但我对如何使用这个问题感到困惑文件/etc/nginx/nginx.conf,从那里一切都有点令人困惑.如果您知道如何遵循这些说明,请告诉我们.