set 集合
Posted Mr.Zuo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了set 集合相关的知识,希望对你有一定的参考价值。
set 是一个无序且不重复的元素集合
访问速度快
解决了重复问题
1 def add(self, *args, **kwargs): # real signature unknown 添加 2 """ 3 Add an element to a set. 4 5 This has no effect if the element is already present. 6 """ 7 pass
例:
s1 = set() s1.add(‘xiaolong‘) print(s1) s1.add(‘xiaolong‘) print(s1)
得:
{‘xiaolong‘}
{‘xiaolong‘}
8 9 def clear(self, *args, **kwargs): # real signature unknown清空所有数据 10 """ Remove all elements from this set. """ 11 pass
12 13 def copy(self, *args, **kwargs): # real signature unknown浅拷贝 14 """ Return a shallow copy of a set. """ 15 pass
16 17 def difference(self, *args, **kwargs): # real signature unknown比对两个set之间的不同、得到一个新set 18 """ 19 Return the difference of two or more sets as a new set. 20 21 (i.e. all elements that are in this set but not the others.) 22 """ 23 pass
例:
s2 = set([‘alex‘, ‘eric‘, ‘tony‘,‘alex‘]) print(s2) s3 = s2.difference([‘alex‘, ‘eric‘]) print(s2) print(s3)
得:
{‘tony‘, ‘alex‘, ‘eric‘}
{‘tony‘, ‘alex‘, ‘eric‘}
{‘tony‘}
24 25 def difference_update(self, *args, **kwargs): # real signature unknown更新本身数据集合、把传进来的数据和本身一样的删掉,没有返回值(删除当前set中的所有包含在 参数集合 里的元素) 26 """ Remove all elements of another set from this set. """ 27 pass
例:
s2 = set([‘alex‘, ‘eric‘, ‘tony‘,‘alex‘]) print(s2) s4 = s2.difference_update([‘alex‘, ‘eric‘])#更新了自己、把以前的和传进来的相同的移除 print(s2) print(s4)
得:
{‘alex‘, ‘tony‘, ‘eric‘}
{‘tony‘}
None
28 29 def discard(self, *args, **kwargs): # real signature unknown移除元素 30 """ 31 Remove an element from a set if it is a member. 32 33 If the element is not a member, do nothing. 34 """ 35 pass
36 37 def intersection(self, *args, **kwargs): # real signature unknown取交集,创建一个新的set 38 """ 39 Return the intersection of two sets as a new set. 40 41 (i.e. all elements that are in both sets.) 42 """ 43 pass 44
45 def intersection_update(self, *args, **kwargs): # real signature unknown取交集、修改原来的set 46 """ Update a set with the intersection of itself and another. """ 47 pass
48 49 def isdisjoint(self, *args, **kwargs): # real signature unknown如果没有交集、返回true 50 """ Return True if two sets have a null intersection. """ 51 pass
52 53 def issubset(self, *args, **kwargs): # real signature unknown是否是子集 54 """ Report whether another set contains this set. """ 55 pass
56 57 def issuperset(self, *args, **kwargs): # real signature unknown是否是父集 58 """ Report whether this set contains another set. """ 59 pass
60 61 def pop(self, *args, **kwargs): # real signature unknown移除 62 """ 63 Remove and return an arbitrary set element. 64 Raises KeyError if the set is empty. 65 """ 66 pass 67 68 def remove(self, *args, **kwargs): # real signature unknown移除 69 """ 70 Remove an element from a set; it must be a member. 71 72 If the element is not a member, raise a KeyError. 73 """ 74 pass
例:
s2 = set([‘alex‘, ‘eric‘, ‘tony‘,‘alex‘]) print(s2) s2.remove(‘alex‘) print(s2)
得:
{‘eric‘, ‘tony‘, ‘alex‘}
{‘eric‘, ‘tony‘}
75 76 def symmetric_difference(self, *args, **kwargs): # real signature unknown差集、创建新对象 77 """ 78 Return the symmetric difference of two sets as a new set. 79 80 (i.e. all elements that are in exactly one of the sets.) 81 """ 82 pass
83 84 def symmetric_difference_update(self, *args, **kwargs): # real signature unknown差集、改变原来 85 """ Update a set with the symmetric difference of itself and another. """ 86 pass 87
88 def union(self, *args, **kwargs): # real signature unknown并集 89 """ 90 Return the union of sets as a new set. 91 92 (i.e. all elements that are in either set.) 93 """ 94 pass 95 96 def update(self, *args, **kwargs): # real signature unknown更新 97 """ Update a set with the union of itself and others. """ 98 pass
以上是关于set 集合的主要内容,如果未能解决你的问题,请参考以下文章
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段