File: class/Workbook/Examples/Lecture5/inter.py
def intersect(seq1, seq2):
res = [] # start with an empty list
for x in seq1: # scan the first sequence
if x in seq2:
res.append(x) # add common items to end
return res
def union(seq1, seq2):
res = map(None, seq1) # copy of seq1 (see ch13)
for x in seq2: # add new items in seq2
if not x in res:
res.append(x)
return res