python之列表集合加减与或的计算
2015-11-19 01:26
633 查看
## set_calc.py
@@用法:
src.txt AA BB CC
des.txt CC DD EE
calc.py src.txt des.txt
import sys import os import re sList = [] dList = [] def getLinesOfFile(fname): fp = open(fname,"r") cnt = fp.read() return re.split(r'\s',cnt) def SubList(aList,bList):# in a ,not in b tmp = [] for a in aList: if a not in bList: tmp.append(a) return tmp def AndList(aList,bList):# in a and in b tmp = [] for a in aList: if a in bList: tmp.append(a) return tmp def OrList(aList,bList):# in a or in b tmp = OnceForList(aList) bList = OnceForList(bList) for a in bList: if a not in tmp: tmp.append(a) return tmp def OnceForList(aList):# ele not repeat in list tmp = [] for a in aList: if a not in tmp: tmp.append(a) return tmp def showList(list): print "len = ",len(list) print "==============================" for it in list: print "item = ",it sList = getLinesOfFile(sys.argv[1]) dList = getLinesOfFile(sys.argv[2]) showList(SubList(dList,sList)) showList(AndList(dList,sList))
@@用法:
src.txt AA BB CC
des.txt CC DD EE
calc.py src.txt des.txt
相关文章推荐
- 4.1 - Python Statements
- python之计算两数的最大公约数和最小公倍数
- python之类定义
- python之转换文本为QR二维码
- python之多线程socket服务实现
- python之socket实现简单的Each服务
- python之auto鼠标/键盘事件
- python之生成文件/目录的md5值
- python之生成Qt pro文件
- python之扫描本地信息到Solr服务
- python之自动生成table网页(行列可指定)
- python之读取Excel数据
- 使用PyCharm配合部署Python的Django框架的配置纪实
- Qpython
- 利用Psyco让Python程序执行更快
- Python IDLE快捷键一览
- Python List+Tuple+Dict+Set小结
- python之自定义爬虫脚本
- python之自动生成图像列表
- python之自动化生成解析ini文件的Qt类