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)))
原文地址:https://www.cnblogs.com/tianqizhi/p/9565890.html
时间: 2024-10-17 23:46:03