import re
with open('2021.8.19.txt','r') as f:
content = f.read()
content = content.split('\n')[:-1]
a = []
b = []
for i in range(len(content)):
if '>' in content[i]:
a.append(content[i])
else:
b.append(content[i])
print(content[i])
lst = []
for el in a:
if lst.count(el) < 1:
lst.append(el)
num = []
for i in range(len(lst)):
num.append(a.count(lst[i]))
c = []
c.append(b[:num[0]])
c.append(b[num[0]:])
for i in range(len(lst)):
for each in range(len(c[i])):
with open(lst[i] + '.txt', 'a') as f:
f.write(c[i][each] + '\n')
实在是头晕,结果不对,但应该可以给你个参考
我有空再看看 |