set集合

Posted 200ML

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了set集合相关的知识,希望对你有一定的参考价值。

‘‘‘ 把W合并到S里面,去除相同的元素,并更新S。 ‘‘‘
w = {11,22,33,44}
s = {33,44,55,66}
s.update(w)
print(s)

‘‘‘ 合并两个列表,去除相同的元素,并赋值給一个变量。 ‘‘‘
w = {11,22,33,44}
s = {33,44,55,66}
e = s.union(w)
print(e)

‘‘‘ 移除s里面和w里面相同的元素,并把不同元素更新到s里面。 ‘‘‘
w = {11,22,33,44}
s = {33,44,55,66}
s.symmetric_difference_update(w)
print(s)

‘‘‘ 对称差集,移除两个列表中相同元素,并赋值給一个变量。 ‘‘‘
w = {11,22,33,44}
s = {33,44,55,66}
e = s.symmetric_difference(w)
print(e)

‘‘‘ 直接移除列表中某个元素,不存在,则报错。 ‘‘‘
w = {11,44,33,67,66}
s = {12,33,55,66}
s.remove(33)
print(s)

‘‘‘ 移除列表元素,并赋值給一个变量 ‘‘‘
w = {11,44,33,67,66}
s = {12,33,55,66}
print(s)
e = s.pop()
print(e)


‘‘‘ 判断s是否是W的父序列,也就是s是不是W的父亲 ‘‘‘
w = {33,66}
s = {12,33,55,66}
e = s.issuperset(w)
print(e)

‘‘‘ 判断s是否是w的子序列,也就是s是不是w的儿子。 ‘‘‘
w = {11,33,66}
s = {33,66}
e = s.issubset(w)
print(e)

‘‘‘ 判断两个set里是否有相同的,没有就返回True,有就返回False ‘‘‘
w = {11,44}
s = {12,33,55,66}
e = s.isdisjoint(w)
print(e)

‘‘‘ 从当前集合直接删除与其不一样的值 ‘‘‘
w = {11,44,33,67,66}
s = {12,33,55,66}
s.intersection_update(w)
print(s)

‘‘‘ 把S里和W里不一样的去掉,重新赋值給e变量 ‘‘‘
w = {11,44,33,67,66}
s = {12,33,55,66}
e = s.intersection(w)
print(e)



‘‘‘把S里和W一样的去掉,重新赋值給e变量‘‘‘
w = {11,44,33,67,66}
s = {12,33,55,66}
e = s.difference(w)
print(e)

‘‘‘ 从当前集合中直接删除与其一样的值 ‘‘‘
w = {11,44,33,67,66}
s = {12,33,55,66}
s.difference_update(w)
print(s)

‘‘‘添加元素‘‘‘
s = {12,33,55,66}
s.add(‘ee‘)
print(s)

s = {12,33,55,66}
s.clear()
print(s)

s = {12,33,55,66}
e = s.copy()
print(e)

‘‘‘ 移除指定元素不存在报错 ‘‘‘
w = {11,44,33,67,66}
s = {12,33,55,66}
s.discard(123)
print(s)

  

‘‘‘ 把W合并到S里面,去除相同的元素,并更新S。 ‘‘‘
w = {11,22,33,44}
s = {33,44,55,66}
s.update(w)
print(s)

‘‘‘ 合并两个列表,去除相同的元素,并赋值給一个变量。 ‘‘‘
w = {11,22,33,44}
s = {33,44,55,66}
e = s.union(w)
print(e)

‘‘‘ 移除s里面和w里面相同的元素,并把不同元素更新到s里面。 ‘‘‘
w = {11,22,33,44}
s = {33,44,55,66}
s.symmetric_difference_update(w)
print(s)

‘‘‘ 对称差集,移除两个列表中相同元素,并赋值給一个变量。 ‘‘‘
w = {11,22,33,44}
s = {33,44,55,66}
e = s.symmetric_difference(w)
print(e)

‘‘‘ 直接移除列表中某个元素,不存在,则报错。 ‘‘‘
w = {11,44,33,67,66}
s = {12,33,55,66}
s.remove(33)
print(s)

‘‘‘ 移除列表元素,并赋值給一个变量 ‘‘‘
w = {11,44,33,67,66}
s = {12,33,55,66}
print(s)
e = s.pop()
print(e)


‘‘‘ 判断s是否是W的父序列,也就是s是不是W的父亲 ‘‘‘
w = {33,66}
s = {12,33,55,66}
e = s.issuperset(w)
print(e)

‘‘‘ 判断s是否是w的子序列,也就是s是不是w的儿子。 ‘‘‘
w = {11,33,66}
s = {33,66}
e = s.issubset(w)
print(e)

‘‘‘ 判断两个set里是否有相同的,没有就返回True,有就返回False ‘‘‘
w = {11,44}
s = {12,33,55,66}
e = s.isdisjoint(w)
print(e)

‘‘‘ 从当前集合直接删除与其不一样的值 ‘‘‘
w = {11,44,33,67,66}
s = {12,33,55,66}
s.intersection_update(w)
print(s)

‘‘‘ 把S里和W里不一样的去掉,重新赋值給e变量 ‘‘‘
w = {11,44,33,67,66}
s = {12,33,55,66}
e = s.intersection(w)
print(e)



‘‘‘把S里和W一样的去掉,重新赋值給e变量‘‘‘
w = {11,44,33,67,66}
s = {12,33,55,66}
e = s.difference(w)
print(e)

‘‘‘ 从当前集合中直接删除与其一样的值 ‘‘‘
w = {11,44,33,67,66}
s = {12,33,55,66}
s.difference_update(w)
print(s)

‘‘‘添加元素‘‘‘
s = {12,33,55,66}
s.add(‘ee‘)
print(s)

s = {12,33,55,66}
s.clear()
print(s)

s = {12,33,55,66}
e = s.copy()
print(e)

‘‘‘ 移除指定元素不存在报错 ‘‘‘
w = {11,44,33,67,66}
s = {12,33,55,66}
s.discard(123)
print(s)

  

‘‘‘ 把W合并到S里面,去除相同的元素,并更新S。 ‘‘‘w = {11,22,33,44}s = {33,44,55,66}s.update(w)print(s)
‘‘‘ 合并两个列表,去除相同的元素,并赋值給一个变量。 ‘‘‘w = {11,22,33,44}s = {33,44,55,66}e = s.union(w)print(e)
‘‘‘ 移除s里面和w里面相同的元素,并把不同元素更新到s里面。 ‘‘‘w = {11,22,33,44}s = {33,44,55,66}s.symmetric_difference_update(w)print(s)
‘‘‘ 对称差集,移除两个列表中相同元素,并赋值給一个变量。 ‘‘‘w = {11,22,33,44}s = {33,44,55,66}e = s.symmetric_difference(w)print(e)
‘‘‘ 直接移除列表中某个元素,不存在,则报错。 ‘‘‘w = {11,44,33,67,66}s = {12,33,55,66}s.remove(33)print(s)
‘‘‘ 移除列表元素,并赋值給一个变量 ‘‘‘w = {11,44,33,67,66}s = {12,33,55,66}print(s)e = s.pop()print(e)

‘‘‘ 判断s是否是W的父序列,也就是s是不是W的父亲 ‘‘‘w = {33,66}s = {12,33,55,66}e = s.issuperset(w)print(e)
‘‘‘ 判断s是否是w的子序列,也就是s是不是w的儿子。 ‘‘‘w = {11,33,66}s = {33,66}e = s.issubset(w)print(e)
‘‘‘ 判断两个set里是否有相同的,没有就返回True,有就返回False ‘‘‘w = {11,44}s = {12,33,55,66}e = s.isdisjoint(w)print(e)
‘‘‘ 从当前集合直接删除与其不一样的值 ‘‘‘w = {11,44,33,67,66}s = {12,33,55,66}s.intersection_update(w)print(s)
‘‘‘ 把S里和W里不一样的去掉,重新赋值給e变量 ‘‘‘w = {11,44,33,67,66}s = {12,33,55,66}e = s.intersection(w)print(e)


‘‘‘把S里和W一样的去掉,重新赋值給e变量‘‘‘w = {11,44,33,67,66}s = {12,33,55,66}e = s.difference(w)print(e)
‘‘‘ 从当前集合中直接删除与其一样的值 ‘‘‘w = {11,44,33,67,66}s = {12,33,55,66}s.difference_update(w)print(s)
‘‘‘添加元素‘‘‘s = {12,33,55,66}s.add(‘ee‘)print(s)
s = {12,33,55,66}s.clear()print(s)
s = {12,33,55,66}e = s.copy()print(e)
‘‘‘ 移除指定元素不存在报错 ‘‘‘w = {11,44,33,67,66}s = {12,33,55,66}s.discard(123)print(s)

 

以上是关于set集合的主要内容,如果未能解决你的问题,请参考以下文章

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段

金蝶handler中 collection 代码片段理解

Alfred常见使用

peptide map DDA和IMS有啥区别

比较 C# 中的字符串片段并从集合中删除项目