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操作串口的方法,python操作串口
- Python合并两个字典的常用方法与效率比较,python合并
- Python使用urllib2模块实现断点续传下载的方法,pythonur
- Python实现的使用telnet登陆聊天室实例,pythontelnet
- 在Python的struct模块中进行数据格式转换的方法,python
- Python基于Tkinter的HelloWorld入门实例,tkinterhelloworld
- Python基于Tkinter实现的记事本实例,pythontkinter实例
- Python实现的彩票机选器实例,python彩票机
- Python抽象类的新写法,Python抽象类写法
- Python的time模块中的常用方法整理,pythontime
评论关闭