文件内容去重操作

#coding= utf-8

alreadyExist = {}


fobj = open('D:\V3\txt\1.txt','r')
line = fobj.readline()
while line:
    alreadyExist[line] = 1
    line = fobj.readline()
fobj.close()

fobj1 = open('D:\V3\txt\2.txt','r')
line = fobj1.readline()
while line:
    alreadyExist[line] = 1
    line = fobj1.readline()
fobj1.close()


fobj2 = open('D:\V3\txt\3.txt','r')
fobj3 = open('D:\V3\txt\4.txt','wb')

line = fobj2.readline()
while line:
    #alreadyExist[line] = 1
    if(alreadyExist.has_key(line)):
        pass
    else:
        fobj3.write(line);
        #fobj3.write('
')
    line = fobj2.readline()
fobj2.close()
fobj3.close()
print('over')

  

原文地址:https://www.cnblogs.com/xiaobaichuangtianxia/p/3804078.html