1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 # Author:Irving 4 list_1 = [1,4,5,7,3,6,9,7] 5 list_1 = set(list_1) 6 7 list_2 = set([2,6,0,66,22,8,4]) 8 print(list_1,list_2) 9 10 #交集 11 print( list_1.intersection(list_2)) 12 13 #并集 14 print(list_1.union(list_2)) 15 16 #差集 in list_1 but not in list_2 17 print(list_1.difference(list_2)) 18 19 #判断子集 20 list_3 = set([1,3,7]) 21 print(list_3.issubset(list_1)) 22 print(list_1.issuperset(list_3)) #父集 23 24 #对称差集(把互相没有的取出来) 25 print(list_1.symmetric_difference(list_2)) 26 27 #add 28 list_1.add(999) 29 print(list_1) 30 31 #update 32 list_1.update([888,777,555]) 33 print(list_1) 34 35 print(list_1.pop()) 36 print(list_1.pop()) 37 print(list_1.pop()) 38 print(list_1.pop()) 39 print(list_1.pop()) 40 41 #discard删除元素不存在不会报错,remove则会 42 list_1.discard(7)