集合的使用
# Author: wang cheng hua list_1 = [1,3,5,7,8,4,5,8,9] list_1 = set(list_1) list_2 = [4,6,8,9,22,33] list_2 = set(list_2) list_3 =[3,5,7] list_3 = set(list_3) print (list_1,list_2) # 交集 print(list_1.intersection(list_2)) #并集 print (list_1.union(list_2)) #差集 is in list_1 not in list_2 print(list_1.difference(list_2)) print(list_2.difference(list_1)) #子集 print(list_1.issubset(list_3)) print(list_3.issubset(list_1)) print(list_3.issuperset(list_1)) #对称差集 print(list_1.symmetric_difference(list_2)) print('-------') list_4 = set([11,12,13]) print(list_3.isdisjoint(list_4)) #运算 #交集 print(list_1 & list_2) #并集 print(list_1 | list_2) #差集 print(list_1-list_2) # in list_1 but not in list_2 #对称差集 print(list_3 ^ list_4) #基本操作 list_1.add(10) print(list_1) list_1.update([66,55,77]) print(list_1) print(len(list_1)) print(list_1.pop()) print(list_1.pop()) print(list_1.discard(100))