ITPub博客

首页 > IT职业 > IT职场 > python 两个文件内容重叠部分

python 两个文件内容重叠部分

IT职场 作者:bluetooth 时间:2021-09-09 09:18:13 0 删除 编辑
f1 = open('a.txt', 'r')
s1 = f1.read()

f2 = open('b.txt', 'r')
s2 = f2.read()

ls = list(set(s1.split('n')) & set(s2.split('n')))

f3 = open('重叠部分.txt', 'w')

for i in ls:
    f3.write(i)
    f3.write('n')

f1.close()
f2.close()
f3.close()

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3402/viewspace-2801954/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 添加php扩展
请登录后发表评论 登录
全部评论

注册时间:2019-07-11

  • 博文量
    280
  • 访问量
    20976