- 论坛徽章:
- 3
|
本帖最后由 sunny7476 于 2013-08-05 12:32 编辑
回复 3# initrdimg
这个求的速度有点快哈,,,刚看到,这是我的版本,文件A和文件B就是你列出的那些内容:- #!/usr/bin/env python
- # coding=utf-8
- fileA=open("A",'rb').readlines()
- fileB=open("B","rb").readlines()
- match = []
- nomatch = []
- for eachlineB in fileB:
- for eachlineA in fileA:
- if eachlineA.rstrip() in eachlineB.rstrip():
- match.append(eachlineB.decode("utf-8").rstrip() )
- for check in fileB:
- if check.decode("utf-8").rstrip() not in match:
- nomatch.append(check.decode("utf-8").rstrip() )
- print (match)
- print ("===========")
- print (nomatch)
复制代码 结果为:- ['我爱你', '一万年', '年年有余']
- ===========
- ['恋爱', '匹配']
复制代码 |
|