#这样试试效果.
def one_data(file):#提取单一文件关注数据
for i in open(file):
yield i.split(":")[1].strip()
def Multiple_Data(*files):#提取多个文件关注数据
for i in files:
for j in one_data(i):
yield j
def dataset(*files): #多文件并集
return set(Multiple_Data(*files))
f1=open("A.txt", "r")
A=f1.readlines()
lst=('B.txt' , 'C.txt' , 'D.txt' , 'E.txt')
B=dataset(*lst)
#B=dataset('B.txt' , 'C.txt' , 'D.txt' , 'E.txt')
with open("new.txt", "w") as c:
for i in A:
if i.strip("\n").split(":")[1] not in B: #A的i行后半部分不在B.txt里.
c.write(i)
f1.close()
[此贴子已经被作者于2021-3-20 14:54编辑过]