Python中的集合set
>>> help(set)
Help on class set in module __builtin__: class set(object)
| set(iterable) --> set object
|
| Build an unordered collection of unique elements.#无序、独一无二的元素
|
| Methods defined here:
|
| __and__(...)
| x.__and__(y) <==> x&y
|
| __cmp__(...)
| x.__cmp__(y) <==> cmp(x,y)
|
| __contains__(...)
| x.__contains__(y) <==> y in x.
|
| __eq__(...)
| x.__eq__(y) <==> x==y
|
| __ge__(...)
| x.__ge__(y) <==> x>=y
|
| __getattribute__(...)
| x.__getattribute__('name') <==> x.name
|
| __gt__(...)
| x.__gt__(y) <==> x>y
|
| __iand__(...)
| x.__iand__(y) <==> x&y
|
| __init__(...)
| x.__init__(...) initializes x; see x.__class__.__doc__ for signature
|
| __ior__(...)
| x.__ior__(y) <==> x|y
|
| __isub__(...)
| x.__isub__(y) <==> x-y
|
| __iter__(...)
| x.__iter__() <==> iter(x)
|
| __ixor__(...)
| x.__ixor__(y) <==> x^y
|
| __le__(...)
| x.__le__(y) <==> x<=y
|
| __len__(...)
| x.__len__() <==> len(x)
|
| __lt__(...)
| x.__lt__(y) <==> x<y
|
| __ne__(...)
| x.__ne__(y) <==> x!=y
|
| __or__(...)
| x.__or__(y) <==> x|y
|
| __rand__(...)
| x.__rand__(y) <==> y&x
|
| __reduce__(...)
| Return state information for pickling.
|
| __repr__(...)
| x.__repr__() <==> repr(x)
|
| __ror__(...)
| x.__ror__(y) <==> y|x
|
| __rsub__(...)
| x.__rsub__(y) <==> y-x
|
| __rxor__(...)
| x.__rxor__(y) <==> y^x
|
| __sizeof__(...)
| S.__sizeof__() -> size of S in memory, in bytes
|
| __sub__(...)
| x.__sub__(y) <==> x-y
|
| __xor__(...)
| x.__xor__(y) <==> x^y
|
| add(...)
| Add an element to a set.
|
| This has no effect if the element is already present.
|
| clear(...)
| Remove all elements from this set.
|
| copy(...)
| Return a shallow copy of a set.
|
| difference(...)
| 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.)
|
| difference_update(...)
| Remove all elements of another set from this set.
|
| discard(...)
| Remove an element from a set if it is a member.
|
| If the element is not a member, do nothing.
|
| intersection(...)
| Return the intersection of two sets as a new set.
|
| (i.e. all elements that are in both sets.)
|
| intersection_update(...)
| Update a set with the intersection of itself and another.
|
| isdisjoint(...)
| Return True if two sets have a null intersection.
|
| issubset(...)
| Report whether another set contains this set.
|
| issuperset(...)
| Report whether this set contains another set.
|
| pop(...)
| Remove and return an arbitrary set element.
| Raises KeyError if the set is empty.
|
| remove(...)
| Remove an element from a set; it must be a member.
|
| If the element is not a member, raise a KeyError.
|
| symmetric_difference(...)
| Return the symmetric difference of two sets as a new set.
|
| (i.e. all elements that are in exactly one of the sets.)
|
| symmetric_difference_update(...)
| Update a set with the symmetric difference of itself and another.
|
| union(...)
| Return the union of sets as a new set.
|
| (i.e. all elements that are in either set.)
|
| update(...)
| Update a set with the union of itself and others.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __hash__ = None
|
| __new__ = <built-in method __new__ of type object at 0x1E1CD668>
| T.__new__(S, ...) -> a new object with type S, a subtype of T
通过下面例子,可以看出:集合是非重复的,集合是无序的。
>>> d=set('chooses')
>>> d
set(['h', 'c', 'e', 's', 'o'])
>>> d
set(['h', 'c', 'e', 's', 'o'])
>>> d
set(['h', 'c', 'e', 's', 'o'])
>>>
如果需要有序的集合,可以改为list:
>>> d=set('chooses')
>>> d
set(['h', 'c', 'e', 's', 'o'])
>>> d
set(['h', 'c', 'e', 's', 'o'])
>>> d
set(['h', 'c', 'e', 's', 'o'])
>>> mylist=list(d)
>>> mylist
['h', 'c', 'e', 's', 'o']
>>> mylist.sort()
>>> mylist
['c', 'e', 'h', 'o', 's']
>>>
Python中的集合set的更多相关文章
- python 中的集合set
python中,集合(set)是一个无序排列,可哈希, 支持集合关系测试,不支持索引和切片操作,没有特定语法格式, 只能通过工厂函数创建.集合里不会出现两个相同的元素, 所以集合常用来对字符串或元组或 ...
- Python中的集合类型分类和集合类型操作符解析
集合类型 数学上,把set称作由不同的元素组成的集合,集合(set)的成员通常被称作集合元素(set elements). Python把这个概念引入到它的集合类型对象里.集合对象是一组无 ...
- python学习之【第七篇】:Python中的集合及其所具有的方法
1.前言 python中的集合set与列表类似,它们最大的区别是集合内不允许出现重复元素,如果在定义时包含重复元素,会自动去重. 集合是无序的,集合中的元素必须是不可变类型.集合可以作为字典的key. ...
- 14.python中的集合
什么是集合?正如其字面的意思,一堆东西集中合并到一起.乍一听貌似和容器没什么差别,嗯,好吧,集合也算是一种容器. 在学习这个容器有什么不同之前,先看看集合是如何创建的: a = set() #可变集合 ...
- python中的集合
在python中,普通集合是可变数据类型 通过以下案例说明: >>> s = {1, 2, 3, 4} >>> id(s) 2108634636808 >&g ...
- 8、python中的集合
集合是python中无序.可变的数据结构.集合与字典类似,集合中的元素必须是可哈希的(等同于字典中的键),也就是说集合中的元素是唯一.不可变的数据类型.这里前面说集合可变,后面又说集合中的元素不可变是 ...
- python中的集合、元组和布尔
#元组,元组跟列表一样,只不过列表可读可写,而元组一般用来只读,不修改#python中不允许修改元组的数据,也包括不能删除其中的元素. t1 = ('a','b','c','d','s','a') & ...
- Python 中的集合 --set
前言 在Python中,我们用[]来表示列表list,用()来表示元组tuple,那{}呢?{}不光可用来定义字典dict,还可以用来表示集合set. 集合 set 集合(set)是一个无序的不重复元 ...
- python 中的集合(set) 详解
在Python set是基本数据类型的一种集合类型,它有可变集合(set())和不可变集合(frozenset)两种. 创建集合set.集合set添加.集合删除.交集.并集.差集的操作都是非常实用的方 ...
- python中set集合
一.set集合的特性 访问速度快 天生解决重复问题 二.set变量申明 s1 = set() s2 = set([1,2,3]) 备注:第二种方式在set类中直接传入一个序列. 三.set类中方法大全 ...
随机推荐
- ThinkSNS+ PHP开发概述
Plus (读音:[plʌs],全称:ThinkSNS+ [θɪŋk es en es plʌs],是 ThinkSNS 系列产品一个重要版本,其软件识别名称为 Plus 即 +) 是一个基于 Lat ...
- 背包DP【bzoj2287】: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Description ftiasch 有 N 个物品, 体积分别是 W1, W2, ..., WN. 由于她的疏忽, 第 i 个物品丢失了. &q ...
- php微信公众号开发简单记录
开发前准备:1.服务器 2.微信公众号测试号(有真实的账号更好) 测试号申请地址:https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/lo ...
- giihub上的关于js的43道题目
参考 https://github.com/lydiahallie/javascript-questions
- input[checkbox],input[radiobox]的一些问题
复选框和文字对不齐:checkbox复选框的一些深入研究与理解: 解决方案:复选框或单选框与文字对齐的问题的深入研究与一 实例:实例.
- 装饰器(Decorator)模式
public interface IDoThings { public void doSomeThing(); } public class DoThings implements IDoThings ...
- 牛客网Java刷题知识点之构造函数是什么、一般函数和构造函数什么区别呢、构造函数的重载、构造函数的内存图解
不多说,直接上干货! 构造函数是什么? 构建创造对象时调用的函数. 构造函数是一种特殊的函数,用来在对象实例化时初始化对象的成员变量. 注意: 创建对象都必须要通过构造函数初始化. 构造函数的特点 ...
- 一般的linux系统默认安装的vim是精简版
一般的linux系统默认安装的vim是精简版(vim-tiny),所以不能配置语法检查等属性或获取在线帮助.需要安装vim-x:x.x.x,vim-common,vim-runtime. :synta ...
- Mybatis的小计
1连接池 一 我的错误想法 poolMaximumIdleConnections 最大活跃连接数 poolMaximumActiveConnections 最大空闲连接数 我一直以为 空闲是一直存在的 ...
- .net中Response.End() 和Response.Redirect("http://dotnet.aspx.cc");
问:什么情况下需要Response.End()语句,加这句有什么好处 答: 首先你要理解Response.End()的意思,它的意思是终止执行下面的语句!但有时不加和加上都一样,但还要加上好,为什么呢 ...