废话不多说,直接上代码
import re
zhangs = []
i = -1
#文件路径需要自己改一下
with open('./我的老千江湖.txt','r',encoding='utf8') as f:
p = f.readlines()
#章节名正则匹配
partten = u'(第\d+章)?'
for line in p:
if(re.match(partten,line).group() != ''):
i += 1
zhangs.append('')
zhangs[i] += line + '\n'
news_li = []
for i in zhangs:
flag = True
for p in news_li:
# 判断章节名前10个字重复就认为章节重复
if(i[:10] == p[:10]):
print(i[:10],p[:10])
flag = False
if(flag):
news_li.append(i)
with open('./我的老千江湖删除重复章节版.txt','a',encoding='utf8') as fp:
for i in news_li:
fp.write(i+'\n')
有问题可以在留言区讨论,我看到了会回复的