Python 求函数(a-b)U(b-a)中两组差分的交点,并求差分集
我试着理解这个问题和答案,但我没有得到它,因为代码从联合开始 这是怎么回事?我不明白这个问题问的是什么Python 求函数(a-b)U(b-a)中两组差分的交点,并求差分集,python,python-3.8,set-operations,Python,Python 3.8,Set Operations,我试着理解这个问题和答案,但我没有得到它,因为代码从联合开始 这是怎么回事?我不明白这个问题问的是什么 def union(a,b): c = [] for i in a: if i not in b: c.append(i) c = c + b c.sort() return c
def union(a,b):
c = []
for i in a:
if i not in b:
c.append(i)
c = c + b
c.sort()
return c
def intersection(a,b):
c = []
for i in a:
if i in b:
c.append(i)
c.sort()
return c
def complement(a,b):
c = a + []
for i in b:
if i in a:
c.remove(i)
c.sort()
return c
def double_complement(a,b):
c = union(a,b)
d = intersection(a,b)
e = complement(c,d)
e.sort()
return e
a = [1,3,5,7,9,2]
b = [2,4,6,8,0,7]
double_complement(a,b)