【发布时间】:2021-03-25 19:05:15
【问题描述】:
我有 2 个文件:stopwords.txt 和 a.txt
我想从文件a.txt 中的文件stopwords.txt 中删除停用词,并用空格分隔。
我该怎么做?这是我试图做的:
def remove_stopwords(review_words):
with open('stopwords.txt') as stopfile:
stopwords = stopfile.read()
list = stopwords.split()
print(list)
with open('a.txt') as workfile:
read_data = workfile.read()
data = read_data.split()
print(data)
for word1 in list:
for word2 in data:
if word1 == word2:
return data.remove(list)
print(remove_Stopwords)
提前致谢
【问题讨论】:
-
欢迎。请查看stackoverflow.com/help/how-to-ask。希望你至少展示你自己已经尝试过的东西
-
嗨,我查看了该链接并尝试使用其中的解决方案。但是,我只有 2 个文件,它不起作用。
标签: python python-3.x