set()集合基本操作
运用频次:☆☆
set是一个无序且不重复元素集,基本操作如下:
1. 创建set集合,会自动转换成set类型
2. add():添加元素
def add(self, *args, **kwargs): # real signature unknown
# 添加元素
"""
Add an element to a set. This has no effect if the element is already present.
"""
pass
3. clear():清除元素
def clear(self, *args, **kwargs): # real signature unknown
#清除元素
""" Remove all elements from this set. """
pass
3. copy():浅拷贝
def copy(self, *args, **kwargs): # real signature unknown
""" Return a shallow copy of a set. """
pass
4. difference():取差集,不更新原集合
def difference(self, *args, **kwargs): # real signature unknown
# 取差集,不更新原集合,重新生成新的集合
"""
Return the difference of two or more sets as a new set. (i.e. all elements that are in this set but not the others.)
"""
pass
5. difference_update():取差集,更新原集合
def difference_update(self, *args, **kwargs): # real signature unknown
# 取差集,更新原集合,不生成新的集合
""" Remove all elements of another set from this set. """
pass
6. discard():删除元素,更新原集合
def discard(self, *args, **kwargs): # real signature unknown
# 删除指定元素,更新原集合
"""
Remove an element from a set if it is a member. If the element is not a member, do nothing.
"""
pass
7. intersection():取交集,返回一个新的集合
def intersection(self, *args, **kwargs): # real signature unknown
# 取交集,不更新原集合,重新生成新集合
"""
Return the intersection of two sets as a new set. (i.e. all elements that are in both sets.)
"""
pass
8. intersection_update():取交集,更新原集合
def intersection_update(self, *args, **kwargs): # real signature unknown
# 取交集,更新原集合
""" Update a set with the intersection of itself and another. """
pass
9. isdisjoint():判断是否有交集,无则返回True
def isdisjoint(self, *args, **kwargs): # real signature unknown
# 若无交集,则返回True
""" Return True if two sets have a null intersection. """
pass
10. issubset():判断是否是子集,是则返回True
def issubset(self, *args, **kwargs): # real signature unknown
# 判断另一集合是否包含该集合,是则返回True
""" Report whether another set contains this set. """
pass
11. issuperset():判断是否是父集,是则返回True
def issuperset(self, *args, **kwargs): # real signature unknown
# 判断该集合是否包含另一集合,是则返回True
""" Report whether this set contains another set. """
pass
12. pop():随机删除一个元素并返回,更新原集合
def pop(self, *args, **kwargs): # real signature unknown
# 随机删除一个元素并返回,更新原集合
"""
Remove and return an arbitrary set element.
Raises KeyError if the set is empty.
"""
pass
13. remove():删除元素,更新原集合
def remove(self, *args, **kwargs): # real signature unknown
# 删除指定元素,无返回值,更新原集合
"""
Remove an element from a set; it must be a member. If the element is not a member, raise a KeyError.
"""
pass
14. symmetric_difference():取差集,不更新原集合
def symmetric_difference(self, *args, **kwargs): # real signature unknown
# 取差集,返回一个新的集合,不更新原集合
"""
Return the symmetric difference of two sets as a new set. (i.e. all elements that are in exactly one of the sets.)
"""
pass
15. symmetric_difference_update():取差集,更新原集合
def symmetric_difference_update(self, *args, **kwargs): # real signature unknown
# 取差集,更新原集合
""" Update a set with the symmetric difference of itself and another. """
pass
16. union():取并集,不更新原集合
def union(self, *args, **kwargs): # real signature unknown
# 取并集,返回一个新的集合,不更新原集合
"""
Return the union of sets as a new set. (i.e. all elements that are in either set.)
"""
pass
17. update():取并集,更新原集合
def update(self, *args, **kwargs): # real signature unknown
# 取并集,更新原集合
""" Update a set with the union of itself and others. """
pass
set()集合基本操作的更多相关文章
- 集合基本操作 Python DAY2
集合本身具有两个特性 1.去重 2.关系测试 列表转集合的两种写法: list_1=[1,2,3,4,1,2,7,8,] list_1=set(list_1) #方法二 list_2=set([1, ...
- JavaScript 集合基本操作
参考 MDN 集合 Array 1. 2种创建数组的方式 var fruits = [] ; var friuits = new Array(); 2. 遍历 fruits.forEach(funct ...
- Java 中的集合接口——List、Set、Map
Java 中的集合接口——List.Set.Map 什么叫集合:集合就是Java API所提供的一系列类的实例,可以用于动态存放多个对象.这跟我们学过的数组差不多,那为什么我们还要学集合,我们看看数组 ...
- python集合类型
集合类型简介 集合也是容器,其内元素都是无序.唯一.不可变的.它常用来做成员测试.移除重复数据.数据计算(比如交集.并集.差集). 集合Set是dict的无value版.集合也使用大括号包围: > ...
- python元组,集合类型,及字典补充
一.元组 元组与列表基本相同,不同之处在于元组只能存不能取,当多个值没有改的需求时,用元组更合适 元组的基本操作 1.创建元组: t = (1, 2, 3, 4, 2,4,) t = (1,) #单个 ...
- Scala集合类型详解
Scala集合 Scala提供了一套很好的集合实现,提供了一些集合类型的抽象. Scala 集合分为可变的和不可变的集合. 可变集合可以在适当的地方被更新或扩展.这意味着你可以修改,添加,移除一个集合 ...
- Python自动化开发 - 字符编码、文件和集合
本节内容 字符编码 文件操作 集合 一.字符编码 1.编码 计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.解决思路:数字与符号建立一对一映射,用不同数字表示不同符号. ASCI ...
- Spark记录-Scala集合
Scala列表 Scala列表与数组非常相似,列表的所有元素都具有相同的类型,但有两个重要的区别. 首先,列表是不可变的,列表的元素不能通过赋值来更改. 其次,列表表示一个链表,而数组是平的. 具有类 ...
- 【python】-- 深浅copy、集合
深浅copy 1.数字.字符串的copy: 赋值(=).浅拷贝(copy)和深拷贝(deepcopy)其实都一样,因为它们永远指向同一个内存地址: >>> import copy & ...
随机推荐
- Python 基础知识(5)
1:引用 当我们把一个变量给另一个变量赋值的时候,不是把A变量中的值给B一份,而是把A变量中的地址给了B,这就是引用.任何牵扯到等号赋值的地方,统统都是引用. a = 100 b = a id(a) ...
- 1-docker基础
docker有三个基本概念:镜像/容器/仓库 镜像:一个完整的root文件系统,但并非一个iso的打包文件,而是使用分层存储.构建镜像时,是一层一层的.新的镜像,也可以在原有镜像上添加新层. 容器:是 ...
- fzu Problem 2198 快来快来数一数 (快速幂+优化)
题目链接: Problem 2198 快来快来数一数 题目描述: 给出n个六边形排成一排,a[i]代表i个六边形能组成的生成树个数,设定s[i]等于a[1]+a[2]+a[3]+....+a[i- ...
- Hdu 2888 Check Corners (二维RMQ (ST))
题目链接: Hdu 2888 Check Corners 题目描述: 给出一个n*m的矩阵,问以(r1,c1)为左上角,(r2,c2)为右下角的子矩阵中最大的元素值是否为子矩阵的顶点? 解题思路: 二 ...
- python_9(模块补充)
第1章 re模块补充 1.1 贪婪匹配:回溯算法 1.2 .*?的用法 1.3 例:分组<name>取值 1.4 匹配整数删除小数 1.5 正则测试地址 第2章 重点模块 2.1 hash ...
- mysql索引命中规则
转于:https://blog.csdn.net/claram/article/details/77574600 首先明确:为什么要用联合索引? 对于查询语句“SELECT E.* FROM E WH ...
- grunt配置详情
这个grunt配置 是我的一个程序员朋友从网上无意间看到的,然后他亲测了下,恩,是可以的.不过我到目前还未测试过是否可以. 一.安装node, 首先确保电脑已有node的环境.然后 运行 npm i ...
- poj3262 Protecting the Flowers
思路: 简单贪心,每次选择性价比最高的. 实现: #include <iostream> #include <cstdio> #include <algorithm> ...
- CSS层叠的问题、标准文档流、伪类选择器
一.层叠的问题 CSS有两个性质: 1.继承性 2.层叠性:选择器的一种选择能力,谁的权重大就选谁 层叠性又分为: 1).选不中:走继承性 (font.color.text.) 继承性的权重是0 若 ...
- MongoDB部署、使用、监控及调优
MongoDB部署 系统环境:CentOS7 下载地址:http://mirrors.163.com/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-DVD ...