python数组交集、并集与不同
2015-06-19 15:49
716 查看
>>> a = [1,2,3]
>>> b = [2,4,5]
>>> list(set(a).intersection(set(b)))
[2]
>>> list(set(a).union(set(b)))
[1, 2, 3, 4, 5]
>>> list(set(a).difference(set(b)))
[1, 3]
>>> list(set(b).difference(set(a)))
[4, 5]
>>>
>>> b = [2,4,5]
>>> list(set(a).intersection(set(b)))
[2]
>>> list(set(a).union(set(b)))
[1, 2, 3, 4, 5]
>>> list(set(a).difference(set(b)))
[1, 3]
>>> list(set(b).difference(set(a)))
[4, 5]
>>>
相关文章推荐
- python链接mysql常见问题汇总
- 【转】Python2.6下安装Mysqldb出现DeprecationWarning: the sets module is deprecated from sets错误解决方案
- python解码\'\\u\'字符串
- 用reindent.py修复python代码缩进(tab键引发的问题)
- python调用的动态连接库的方法(ctypes)
- Python urllib2 设置超时时间
- Python urllib2 设置超时时间
- 利用Python内置函数getattr轻松实现分发模式
- python获取文件属性(转)
- Python和Django的详细安装步骤(转)
- python和数据库连接(转)
- 使用Python來控制MS Word
- python 删除目录
- python批量替换页眉页脚
- virtualenv中安装python3.2的numpy包
- 基于python:opencv简单图片操作
- python资料汇总
- Python学习 之 函数
- Python学习路径8——Python对象2
- python实例26[计算MD5]