运用频次:☆☆

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()集合基本操作的更多相关文章

  1. 集合基本操作 Python DAY2

    集合本身具有两个特性 1.去重  2.关系测试 列表转集合的两种写法: list_1=[1,2,3,4,1,2,7,8,] list_1=set(list_1) #方法二 list_2=set([1, ...

  2. JavaScript 集合基本操作

    参考 MDN 集合 Array 1. 2种创建数组的方式 var fruits = [] ; var friuits = new Array(); 2. 遍历 fruits.forEach(funct ...

  3. Java 中的集合接口——List、Set、Map

    Java 中的集合接口——List.Set.Map 什么叫集合:集合就是Java API所提供的一系列类的实例,可以用于动态存放多个对象.这跟我们学过的数组差不多,那为什么我们还要学集合,我们看看数组 ...

  4. python集合类型

    集合类型简介 集合也是容器,其内元素都是无序.唯一.不可变的.它常用来做成员测试.移除重复数据.数据计算(比如交集.并集.差集). 集合Set是dict的无value版.集合也使用大括号包围: > ...

  5. python元组,集合类型,及字典补充

    一.元组 元组与列表基本相同,不同之处在于元组只能存不能取,当多个值没有改的需求时,用元组更合适 元组的基本操作 1.创建元组: t = (1, 2, 3, 4, 2,4,) t = (1,) #单个 ...

  6. Scala集合类型详解

    Scala集合 Scala提供了一套很好的集合实现,提供了一些集合类型的抽象. Scala 集合分为可变的和不可变的集合. 可变集合可以在适当的地方被更新或扩展.这意味着你可以修改,添加,移除一个集合 ...

  7. Python自动化开发 - 字符编码、文件和集合

    本节内容 字符编码 文件操作 集合 一.字符编码 1.编码 计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.解决思路:数字与符号建立一对一映射,用不同数字表示不同符号. ASCI ...

  8. Spark记录-Scala集合

    Scala列表 Scala列表与数组非常相似,列表的所有元素都具有相同的类型,但有两个重要的区别. 首先,列表是不可变的,列表的元素不能通过赋值来更改. 其次,列表表示一个链表,而数组是平的. 具有类 ...

  9. 【python】-- 深浅copy、集合

    深浅copy 1.数字.字符串的copy: 赋值(=).浅拷贝(copy)和深拷贝(deepcopy)其实都一样,因为它们永远指向同一个内存地址: >>> import copy & ...

随机推荐

  1. JSP | 基础 | 新建Hello world 的三种方式

    第一种: 直接写一个 test.jsp 文件到ROOT文件目录下,内容如下,访问 “http://localhost:8080/test.jsp” <%-- Licensed to the Ap ...

  2. css3 background-size属性--ie兼容

    css3 background-size属性--ie兼容 safari浏览器对background-size 属性显示原始大小 background-size: cover not working o ...

  3. Hdu 4513 吉哥系列故事——完美队形II (manacher变形)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4513 题目描述: 打完题目描述了,点开题目,发现题目是中文,orz.jpg.果断又删掉了,习惯真可怕 ...

  4. Hdu 4778 Gems Fight! (状态压缩 + DP)

    题目链接: Hdu 4778 Gems Fight! 题目描述: 就是有G种颜色,B个背包,每个背包有n个宝石,颜色分别为c1,c2............两个人轮流取背包放到公共容器里面,容器里面有 ...

  5. JavaScript整理

    JavaScript是脚本语言 常用对话框: alert()——警告对话框,作用是弹出一个警告对话框 confirm()——带确定和取消按钮,返回True或false prompt()——弹出一个可以 ...

  6. Web前端攻防,一不小心就中招了

    随着各浏览器安全功能的提高,前端防御面临的问题也没有之前那么复杂,但浏览器的防御措施并不能百分百的保证网站的安全. 浏览器的XSS Auditor,使得反射型xss几乎被废:CSP(Content-S ...

  7. Android Activity生命周期的几个问题

      每一个Android开发者都应该知道,android系统有四个重要的基本组件,即Activity(活动).Service(服务).Broadcast Receive(广播接收器)和Content ...

  8. C/C++ static

    C/C++中static关键字作用总结 1.先来介绍它的第一条也是最重要的一条:隐藏.(static函数,static变量均可) 当同时编译多个文件时,所有未加static前缀的全局变量和函数都具有全 ...

  9. XML基本概念及增删改查操作

    一.概念及特征: 1. XML 指可扩展标记语言(Extensible Markup Language),用户可以自己定义标签.XML 被设计用来传输和存储数据,而 HTML 用于格式化并显示数据,并 ...

  10. 在CNN网络中roi从原图映射到feature map中的计算方法

    在使用fast rcnn以及faster rcnn做检测任务的时候,涉及到从图像的roi区域到feature map中roi的映射,然后再进行roi_pooling之类的操作.比如图像的大小是(600 ...