已知两个文本文档,求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))

 

相关文章:

  • 2021-09-20
  • 2022-12-23
  • 2021-08-04
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2022-01-31
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2021-04-17
  • 2021-09-08
相关资源
相似解决方案