用python从多个文件中提取有用信息到一个文件中

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

f0=open("STAS_FOR_mul_div.txt","r")
f1=open("STAS_FOR_nqueen.txt","r")
f2=open("STAS_FOR_registers_dis.txt","r")
f3=open("STAS_FOR_registers_dis0.txt","r")
f4=open("result.txt","w")

dicts={}
cnt=0

lines0=f0.readlines()
lines1=f1.readlines()
lines2=f2.readlines()
lines3=f3.readlines()
f0.close()
f1.close()
f2.close()
f3.close()
for line0 in lines0:
	if '%' in line0:
		a=line0.find(':')
		b=line0[0:a]
		#if not dicts.hasKey(b):
		if not b in dicts:
			dicts[b]=1
			cnt=cnt+1
			#f4.write(b+'\n')
for line1 in lines1:
	if '%' in line1:
		a=line1.find(':')
		b=line1[0:a]
		#if not dicts.has_key(b):
		if not b in dicts:
			dicts[b]=1
			cnt=cnt+1
			#f4.write(b+'\n')
for line2 in lines2:
	if '%' in line2:
		a=line2.find(':')
		b=line2[0:a]
		#if not dicts.has_key(b):
		if not b in dicts:
			dicts[b]=1
			cnt=cnt+1
			#f4.write(b+'\n')
for line3 in lines3:
	if '%' in line3:
		a=line3.find(':')
		b=line3[0:a]
		#if not dicts.has_key(b):
		if not b in dicts:
			dicts[b]=1
			cnt=cnt+1
			#f4.write(b+'\n')
for i in range(5):
        s='STAS_FOR_test'+str(i)+'.txt'
        f=open(s,'r')
        lines=f.readlines()
        f.close()
        for line in lines:
                if '%' in line:
                        a=line.find(':')
                        b=line[0:a]
                        if not b in dicts:
                                dicts[b]=1
                                cnt=cnt+1
                                #f4.write(b+'\n')

dicts=sorted(dicts.items(),key=lambda item:item[0],reverse=False)
for item in dicts:
        f4.write(item[0]+'\n')
f4.write('\n'+str(cnt)+'\n')
f4.close()