Python求两个文本文件以行为单位的交集、并集与差集的方法
发布时间:2020-09-01 14:15:19 所属栏目:Python 来源:互联网
导读:本文实例讲述了Python求两个文本文件以行为单位的交集、并集与差集的方法。分享给大家供大家参考。具体实现方法如下:
本文实例讲述了Python求两个文本文件以行为单位的交集、并集与差集的方法。分享给大家供大家参考。具体实现方法如下: s1 = set(open('a.txt','r').readlines()) s2 = set(open('b.txt','r').readlines()) print 'ins: %s'%(s1.intersection(s2)) print 'uni: %s'%(s1.union(s2)) print 'dif: %s'%(s1.difference(s2).union(s2.difference(s1))) 希望本文所述对大家的Python程序设计有所帮助。 (编辑:百色站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- python实现数组插入新元素的方法
- 版本控制 – Mercurial日志界面
- flask:wsgi-middleware vs before_和after_request()
- python – UnicodeDecodeError:’utf8’编解码器无法解码位
- Python3如何通过唯一键连接两个dicts列表
- python – django auth用户截断电子邮件字段
- python – Aiohttp,Asyncio:RuntimeError:事件循环已关闭
- 在Django-South中,Pesky“Table’my_table’已经存在”
- python – 每个bin中具有相同点数的直方图
- python – pandas:用loc迭代DataFrame索引