整理一些对于集合基本操作供大家参考
list_1=[1,4,3,6,3,6,5,8]
print(list_1)
list_1 = set(list_1) #将列表转换为集合,去同
list_2 = set([24,2,3,6,7])
print(list_1,list_2)
list_3 = list_1.intersection(list_2)#取两个集合的交集(list_1 & list_2 )
print(list_3)
print(list_1.union(list_2)) #取并集(list_1 | list_2 )
list_4 = (list_1.difference(list_2))#求差集(list_1 - list_2 )
print(list_4)
print(list_2.difference(list_1))
print(list_1.symmetric_difference(list_2))#求对称差集(list_1 ^ list_2 )
print(list_1.difference_update(list_2))