#集合:1.去重 2.关系测试:交集、并集、差集
list_1=[1,2,4,5,6,3,3,2,5]
list_1=set(list_1)
print(list_1,type(list_1))
list_2=[2,4,6,8,9]
list_2=set(list_2)
print(list_2)
#交集
print(list_1.intersection(list_2))
#并集
print(list_1.union(list_2))
#差集 in list_1 but not in list_2
print(list_1.difference(list_2))
#差集 in list_2 but not in list_1
print(list_2.difference(list_1))
#对称差集(并集-交集)
print(list_1.symmetric_difference(list_2))
print(list_1 & list_2)#交集
print(list_1 | list_2)#并集
print(list_1 - list_2)#差集
print(list_1 ^ list_2)#对称差集
#判断子集
list_3 = set([1,3])
print(list_3.issubset(list_1))
print(list_1.issuperset(list_2))
#判断是否没有交集
print(list_2.isdisjoint(list_3))
print(list_1.isdisjoint(list_2))
list_1.add(123) #添加一项
list_1.update([111,222,444]) #添加多项
print(list_1)
# 删除
list_1.remove(1)
print(list_1.pop())
print(list_1)
list_2.discard(9)
print(list_2)
print(len(list_1))
#判断某个元素是否在集合中
x=123
print(x in list_1)