Information:
System version : Windows 10 64-bit
Python version : Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
Python version : Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
Code:
def unique(a):
return list(set(a))
def intersect(a, b):
return list(set(a) & set(b))
def union(a, b):
return list(set(a) | set(b))
a = [1,2,3,4,4]
b = [2,3,5]
print( unique(a) )
print( intersect(a, b) )
print( union(a, b) )
Result:
[1, 2, 3, 4]
[2, 3]
[1, 2, 3, 4, 5]
沒有留言:
張貼留言