python 求两个list的差集,并集和交集
来源:互联网 发布:电脑网络异常怎么办 编辑:程序博客网 时间:2024/05/16 13:50
比如,现在有两个list类型:
a_list = [1,2,3,4]b_list = [1,4,5]
一. 差集
很明显结果是[2,3,5],下面我们说一下具体方法。
方法a.正常法:
ret_list = [] for item in a_list: if item not in b_list: ret_list.append(item)
方法b.简化版:
ret_list = [item for item in a_list if item not in b_list]
方法c.高级版:
ret_list = list(set(a_list)^set(b_list))
二. 并集
很明显结果是[1,2,3,4,5],下面是具体方法:
ret_list = list(set(a_list).union(set(b_list)))
三. 交集
很明显结果是[1,4],下面是具体方法:
ret_list = list((set(a_list).union(set(b_list)))^(set(a_list)^set(b_list)))
0 0
- Python 求两个 list 的交集和差集
- python 求两个list的差集,并集和交集
- python 求两个list的差集,并集和交集
- python中求两个List的交集、并集和差集
- python 两个list 求交集,并集,差集
- python 两个list 求交集,并集,差集
- python 两个list求取交集、并集和差集
- Python求两个list的差集、交集与并集的方法
- Python求两个list的差集、交集与并集的方法
- Python求两个list的差集、交集与并集的方法(转)
- 求两个list的交集和差集
- java-----求两个list的交集、并集、和差集
- 求两个集合的交集、差集和并集
- Python -- 两个列表的差集、并集和交集
- python list 求交集 差集 并集
- uniq 求两个文件的交集,并集,差集
- java求两个数组的并集、交集、差集
- linux求两个文件的交集,并集,差集
- Pomelo async waterfall
- eclipse快捷键,eclipse快捷键大全
- procd
- java异常
- Python 命令行工具 -- click
- python 求两个list的差集,并集和交集
- Python 的 defaultdict 模块和 namedtuple 模块(xianglong.me)
- Android学习——ClickableSpan点击链接事件 改超链接颜色
- 数组复制
- Cocos2d-x 读取网络图片创建精灵
- [算法之排序]三向切分的快速排序算法(java实现)
- "Unhandled exception in app.exe (QtGuid4.dll): 0xC0000005: Access Violation"错误解决
- shell 暂停等待输入,根据输入进入不同分支
- openwrt交叉编译