Python-set函数
来源:互联网 发布:windows 10桌面太亮 编辑:程序博客网 时间:2024/06/05 07:45
set函数生成的是一个无序不重复的元素集,基本功能为关系测试和消除重复元素。集合对象还支持union(联合), intersection(交), difference(差)和sysmmetric difference(对称差集)等数学运算。
例如:
消除重复值:
a = [1, 2, 3, 4, 5, 6, 2, 4, 2, 1, 5, 3, 2]b = set(a)print(b)>>{1, 2, 3, 4, 5, 6}
交集:
x = set([1, 4, 5, 2, 3])y = set([1, 6, 3, 8])z = x&y>>z={1, 3}
并集:
x = set([1, 4, 5, 2, 3])y = set([1, 6, 3, 8])z = x|y>>z={1, 2, 3, 4, 5, 6, 8}
差集:
x = set([1, 4, 5, 2, 3])y = set([1, 6, 3, 8])z = x-y>>z={2, 4, 5}
阅读全文
0 0
- Python-set函数
- Python set()函数
- Python set()函数详解
- python: set函数
- Python-set函数
- python map set函数用法
- Python中set函数的使用
- Python标准库:内置函数set([iterable])
- python基础III(dict、set、函数)
- python中set()函数的用法
- python--set集合下的函数
- 00106 python函数:set()集合
- python set() 函数-leetcode217 contains duplicate
- python中set()函数的用法
- Python Set
- python set
- python set
- python--set
- spring aop实现权限管理
- 刚刚发布的Bing国际版把百度搜索抛到后面,都来感受一下
- G
- 互联网DSP广告系统架构及关键技术解析 | 广告行业资深架构师亲述
- DIV+CSS上中下左中右布局案例
- Python-set函数
- opencv实现人脸眼睛的检测
- 一些关于logging部分的代码笔记以及讲解
- scikit-learn 常用模型介绍及使用(下)
- Android ScrollView去掉滚动条及ScrollView属性
- Android流失布局
- Oracle数据库整理笔记
- idea使用maven构建mybatis程序遇到的几个问题
- 现代操作系统在之死锁