python3 得到a.txt中有的而b.txt中没有的汉字

已知两个文本文档,求a.txt中有的而b.txt中没有的汉字

#读取list1中的汉字
f1=open('/Users/tanchao/Documents/pythonwork/tensorflow/list1.txt')
ftext1=f1.read()
length1=len(ftext1)

#读取list2中的汉字
f2=open('/Users/tanchao/Documents/pythonwork/tensorflow/list2.txt')
ftext2=f2.read()
length2=len(ftext2)

#打开list3,空的txt文件,存最后的结果
fl=open("list3.txt","w")
str_temp=[]

#将list1中有的而list2没有的存到list3中
for i in range (length1):
    if ftext1[i] not in ftext2:
        str_temp.append(ftext1[i])
        fl.write(ftext1[i])

#输出list3中有多少个字
print (len(str_temp))
原文地址:https://www.cnblogs.com/shixisheng/p/9258685.html