def find_samenumber(list1,list2):
A = set(list1).intersection(set(list2)) #交集
B = set(list1).union(set(list2)) # 并集
C = set(list1).difference(set(list2)) #差集,在list1中但不在list2中的元素
D = set(list2).difference(set(list1)) #差集,在list2中但不在list1中的元素
return A,B,C,D
if __name__=='__main__':
list1=[9,6,4,2,3,5,7,0,1]
list2=[9,5,3,10]
print(find_samenumber(list1,list2))
输出结果:
({9, 3, 5}, {0, 1, 2, 3, 4, 5, 6, 7, 9, 10}, {0, 1, 2, 4, 6, 7}, {10})