python list 求交集 差集 并集
2017-07-04 17:19
260 查看
#!/usr/bin/env python3 # -*- coding: utf-8 -*- ' a test module ' __author__ = 'Zhang Shuai' a = [1,2,3,4] b = [3,4,5,6] ''' 求交集 ''' #方法1 c = [i for i in a if i in b] #方法2 c = list(set(a).intersection(set(b))) ''' 求并集 ''' c = list(set(a).union((set(b)))) ''' 求差集 ''' c = [i for i in a if i not in b]+[j for j in b if j not in a] ''' 在a中不在b中 ''' c = list(set(a).difference(set(b)))
相关文章推荐
- python两个 list 获取交集,并集,差集的方法
- Python list 交集,并集,差集
- python 两个list求取交集、并集和差集
- python中求两个List的交集、并集和差集
- python 两个list 求交集,并集,差集
- Python求两个list的差集、交集与并集的方法
- python list差集,交集,并集
- python取两个list的交集并集差集
- python两个 list 获取交集,并集,差集的方法
- python两个 list 获取交集,并集,差集的方法.
- Python求两个list的差集、交集与并集的方法
- python 获得两个数组(List)交集、并集与差集
- python list 差集,并集,交集......
- python 两个list 求交集,并集,差集
- (每天一句python)两个list的交集、并集、差集
- python两个 list 获取交集,并集,差集的方法
- Python求两个list的差集、交集与并集的方法(转)
- python两个 list 获取交集,并集,差集的方法.
- Python求两个list的差集、交集与并集的方法
- python 求两个list的差集,并集和交集