python集合类型set
set 类型的简单粗暴取出并集合交集 | &
li=[11,22,33]
n_li=[44,55]
b= (list(set(li)&set(n_li)))
b2=set(li).intersection(n_li)
print (b2,b)
s = set()
s={1,2,3}
s.add(4) #往集合里面添加元素,如果存在的话不重复添加,无序。
s.difference_update(b) #s集合对比b集合,并更新S集合,只保留S不重复的部分。
n=s.difference (b) #n值等于两个集合对比,s集合比b集合多出的元素。
s.symmetric_difference(b) #把2个不交集的部分合在一起。
intersection #和上面一条相反,取其交集
class set(object): """ set() -> new empty set object set(iterable) -> new set object Build an unordered collection of unique elements. """ 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 def clear(self, *args, **kwargs): # real signature unknown """ Remove all elements from this set. 清除内容""" pass def copy(self, *args, **kwargs): # real signature unknown """ Return a shallow copy of a set. 浅拷贝 """ pass def difference(self, *args, **kwargs): # real signature unknown """ Return the difference of two or more sets as a new set. A中存在,B中不存在 (i.e. all elements that are in this set but not the others.) """ pass def difference_update(self, *args, **kwargs): # real signature unknown """ Remove all elements of another set from this set. 从当前集合中删除和B中相同的元素""" pass 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 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 def intersection_update(self, *args, **kwargs): # real signature unknown """ Update a set with the intersection of itself and another. 取交集并更更新到A中 """ pass def isdisjoint(self, *args, **kwargs): # real signature unknown """ Return True if two sets have a null intersection. 如果没有交集,返回True,否则返回False""" pass def issubset(self, *args, **kwargs): # real signature unknown """ Report whether another set contains this set. 是否是子序列""" pass def issuperset(self, *args, **kwargs): # real signature unknown """ Report whether this set contains another set. 是否是父序列""" pass def pop(self, *args, **kwargs): # real signature unknown """ Remove and return an arbitrary set element. Raises KeyError if the set is empty. 移除元素 """ pass 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 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 def symmetric_difference_update(self, *args, **kwargs): # real signature unknown """ Update a set with the symmetric difference of itself and another. 对称差集,并更新到a中 """ pass 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 def update(self, *args, **kwargs): # real signature unknown """ Update a set with the union of itself and others. 更新 """ passpython集合类型set的更多相关文章
- Python集合类型的操作与应用
Python集合类型的操作与应用 一.Python集合类型 Python中的集合类型是一个包含0个或多个数据项的无序的.不重复的数据组合,其中,元素类型只能是固定数据类型,如整数.浮点数.字符串.元组 ...
- 代码与图详解性能之Python集合类型(list tuple dict set generator)
Python内嵌的集合类型有list.tuple.set.dict. 列表list:看似数组,但比数组强大,支持索引.切片.查找.增加等功能. 元组tuple:功能跟list差不多,但一旦生成,长度及 ...
- python集合类型
集合类型简介 集合也是容器,其内元素都是无序.唯一.不可变的.它常用来做成员测试.移除重复数据.数据计算(比如交集.并集.差集). 集合Set是dict的无value版.集合也使用大括号包围: > ...
- 遇见Python集合类型
Python目前有两种内置集合类型,set和frozenset. Ⅰ.两者区别 set是可变的,没有哈希值,其内容可以使用add()和remove()这样的方法来改变,所以不能被用作字典的键或其他集合 ...
- 《Python核心编程》 第七章 映射和集合类型 - 习题
课后习题 7–1. 字典方法.哪个字典方法可以用来把两个字典合并到一起? 答: dict1 = {' :' python' } dict2 = {' :"hello" } dict ...
- python set type 集合类型的数据介绍 (set frozenset)
python支持数学中的集合概念,如:通过in,not in 可以检查某元素是否在,不在集合中. python有两种集合类型,set(可以变的,不能哈希,不能用作字典的key),frozenset ...
- Python核心编程(第七章)--映像和集合类型
字典:它是一个容器类型,能存储任意个数的Python对象,也包括其他容器类型,Python的字典是作为可变的哈希表实现的 映像类型中的数据是无序排列的 可以用工厂方法dict()来创建字典,也可以 ...
- Python基础-字符串、集合类型、判断、深拷贝与浅拷贝、文件读写
字符串 1.定义三个变量: 2.交换两个变量值 1)引入第三个变量: 2)Python引入第三方变量: 3)不引入第三方变量: 3. isalpha 是否是汉字或字母 4.Isalnum 是否是汉字 ...
- 第二百九十九节,python操作redis缓存-SortSet有序集合类型,可以理解为有序列表
python操作redis缓存-SortSet有序集合类型,可以理解为有序列表 有序集合,在集合的基础上,为每元素排序:元素的排序需要根据另外一个值来进行比较,所以,对于有序集合,每一个元素有两个值, ...
随机推荐
- web前端开发资源整理
webpack中文文档 http://webpackdoc.com/index.html 饿了么UI http://mint-ui.github.io/#!/zh-cn http://element. ...
- [转]有关WorldWind1.4的worldwind.cs窗口设计器打开错误的解决方法
Solution for Designer error when opening WorldWind.cs in WW1.4.0 When I load the WW project in my Vi ...
- Android调用基于.net的WebService
在实际开发项目中,有时候会为Android开发团队提供一些接口,一般是以asmx文件的方式来承载.而公布出去的数据一般上都是标准的json数据.但是在实际过程中,发现Android团队那边并不是通过将 ...
- 如何在Ubuntu 14.04中安装最新版Eclipse
想必很多开发人员都知道,Ubuntu 软件源中提供的并不是最新版本的 Eclipse,本教程就教大家如何在 Ubuntu 14.04 中快速安装 Eclipse 官方发布的最新版本. 到目前为止,Ec ...
- 信息安全系统设计第二次&第四次实验
实验二 固件设计 实验步骤: 环境配置如同实验一,承接实验一. 1.在虚拟机中编译代码.对于多线程相关的代码,编译时需要加-lpthread 的库. 2.下载调试在超级终端中运行可执行文件 pthr ...
- eclipse的一些初始化设置
eclipse下载地址:http://www.eclipse.org/ 添加java注释模板 codetemplates.xml:Window->Preferences->Java-> ...
- 4.HBase In Action 第一章-HBase简介(1.1.2 数据创新)
As we now know, many prominent internet companies, most notably Google, Amazon, Yahoo!, and Facebook ...
- 关于使用Css设置Canvas画布大小的问题
问题分析 我们在调整画布大小时,希望画布中的图形保持不变,只是改变画布本身的大小.但是如果使用Css设置画布大小,则会出现问题. 问题描述 如果使用Css设置Canvas画布的大小,则导致画布按比例缩 ...
- php 正则表达式捕获组与非捕获组
熟练掌握正则表达式是每个程序员的基础要求,对于每个初学者来说会被正则表达式一连串字符弄得头晕眼花.博主便会如此,一直对正则表达式有种莫名的恐惧.近来看到另一位博友写的 <php正则表达式> ...
- 新年奉献MVC+EF(CodeFirst)+Easyui医药MIS系统
本人闲来无事就把以前用Asp.net做过的一个医药管理信息系统用mvc,ef ,easyui重新做了一下,业务逻辑简化了许多,旨在加深对mvc,ef(codefirst),easyui,AutoMap ...