第一次尝试使用jieba,尝试对分词后的文本去停用词
import jieba
stopwords={}.fromkeys([line.rstrip() for line in open("E:\python\mylist.txt")])
file_object=open(r"E:\python\list.txt",'r',encoding='utf-8-sig').read().split("\n")
Rs=[]
for i in range(len(file_object)-1):
result=[]
seg_list=jieba.cut(file_object[i])
for w in seg_list:
if w not in stopwords and w !=" ":
result.append(w)
Rs.append(result)
with open(r'E:\python\afterstopword.txt','w+')as f :
for i in after_text:
f.write(i)
运行不报错,e盘也出现了新文本只是和没去停用词的文本一模一样。