python 集合set的创建,更改,遍历,元算合并,交集,补集
来源:互联网 发布:小学网络教学 编辑:程序博客网 时间:2024/06/02 07:05
python 集合set的创建,更改,遍历,元算合并,交集,补集
set的创建,set不允许有重复的元素
s = set('cheershopa') 可以修改的set,t = frozenset('bookshopa') 不可须该的setr = set([1,2,3,34,15,25,35,45,75]) 列表转化到sett = {} 空seto = set([]) 空set
set的联合 交集 差补
s | t 求s 与 t的并集 结果和s的类型一样s & t 求 s 与 t的交集,结果是s和类型一样s - t 求 s 与 t 的差补 结果和s的类型一样s.union(t)s.intersection(t)s.difference(t)s.copy()s.superset(t)s.subset(t)s |= ts &= ts -= t
set的内建方法help(set)
>>> help(set) Help on class set in module __builtin__:class set(object) | set() -> new empty set object | set(iterable) -> new 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 help(type(x)) 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 or more sets as a new set. | | (i.e. elements that are common to all of the 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> | T.__new__(S, ...) -> a new object with type S, a subtype of T
0 0
- python 集合set的创建,更改,遍历,元算合并,交集,补集
- python求补集合、交集、并集
- Python--Python 集合set()添加删除、交集、并集、集合
- python-set()集合操作(创建、添加、删除、交集、并集、差集、对称差集)
- 合并有交集的集合
- python 集合 并集、交集 Series list set 转换
- js 集合的交集、补集、差集、去重
- 集合求取并集交集补集
- list集合交集 并集 补集
- JavaScript Set集合的并集,交集,差集
- 【PAT1063】Set Similarity 求两集合的交集、并集
- Python 集合set添加删除、交集、并集、集合操作符号
- Python 集合set()添加删除、交集、并集、集合操作详解
- Python 集合set()添加删除、交集、并集、集合操作详解
- 给定一系列字符串集合,合并有交集的集合,合并完后集合之间无交集
- Set集合的遍历
- set集合的遍历
- python set集合运算(交集,并集,差集,对称差集)
- Log4J.xml
- 学习阶段总结
- PAT乙级1042
- CS231n课程笔记翻译:神经网络笔记1
- PSI授权HTTPS
- python 集合set的创建,更改,遍历,元算合并,交集,补集
- #分数阶Fourier变换的总体认知(From 陶然著)
- [生存志] 第114节 韩信围垓下
- 挨踢部落第二期:大数据在医疗领域的应用和实践
- Android开发基础知识整理之UI与Fragment
- 写程序输出8皇后问题的所有排列,要求使用非递归的深度优先遍历。
- HDU 1556 树状数组
- HTTP协议之报文格式
- 第一个Hello Vue!