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. 更新 """
pass
python集合类型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有序集合类型,可以理解为有序列表 有序集合,在集合的基础上,为每元素排序:元素的排序需要根据另外一个值来进行比较,所以,对于有序集合,每一个元素有两个值, ...
随机推荐
- 使用log4j将日志写入数据库并发送邮件
参考: 快速了解Log4J 1.log4j的初始配置 参考该问的配置即可完整的实现写入数据库及发送邮件的功能 a.写入数据库需要配置相应的jar包,数据库类型不同,请使用指定的数据库配置,该文仅限于o ...
- HTTP基础(一):如何使用浏览器network查看请求和响应的信息
一. 问题描述 HTTP作为前端开发与后开发链接的载体,其重要性不言而喻,今天我不复习关于HTTP自身的一些知识,只复习如何解读浏览器自带的的抓包工具(查看请求信息与响应信息)network. 二. ...
- react-native 的微信SDK辅助包,支持微信登录、微信分享、微信支付
微信SDK集成示例,现已完成微信授权登录,之后将陆续包装分享等其他功能. ReactNative高级交流群 127482131 或访问 http://blog.1ygowu.com ReactNat ...
- Activiti系列: 如何给内置表单添加字段类型
对于内置的表单,除了原来支持的几种数据类型(string, long, enum, date, boolean, collection)之外,还可以自定义数据类型,比如增加一个javascript数 ...
- iOS从App跳转至系统设置菜单各功能项的编写方法讲解
跳到系统设置里的WiFi界面 info里面设置: 在项目中的info.plist中添加 URL types 并设置一项URL Schemes为prefs,如下图 代码: 复制代码 代码如下: NSUR ...
- IOS开发之——登录加密也许用到的,反转字符串
- (NSString *)stringByReversed{// NSMutableString *s = [NSMutableString string];// for (NSUInt ...
- http长链接与短链接
http://www.cnblogs.com/cswuyg/p/3653263.html keep-live模式 这个博客写的很全:http://www.cnblogs.com/skynet/arch ...
- 附加到iis进程调试时找不到w3wp.exe
在进程列表的下面,有个show processes in all sessions,把它勾上就能看到了
- C#基础知识系列一(goto、i++、三元运算符、ref和out、String和string、重载运算符)
前言 这两天在网上看到的总结很多,尤其是博客园中的,很多很多,也给了我很多的启发,当然自己也总结过,而且有很多人也给与我一些意见和看法.不管怎样,自己还是先把所谓的基础知识加强巩固下吧. 2014年的 ...
- 第二十六课:jQuery对事件对象的修复
因为原生的event对象,在不同浏览器下,有不同的属性和方法,因此需要用jQuery进行兼容. jQuery在这里分两步走,首先创建一个伪事件类jQuery.Event(jQuery里面自定义的事件类 ...