码迷,mamicode.com
首页 > 其他好文 > 详细

set集合

时间:2016-12-19 11:35:00      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:blog   highlight   相同   discard   remove   判断   存在   super   报错   

‘‘‘ 把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集合

标签:blog   highlight   相同   discard   remove   判断   存在   super   报错   

原文地址:http://www.cnblogs.com/cloniu/p/6196453.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!