用列表推导式来写
list1 = [1,3,65,2,7]
list2 = [3,2,5,4]
c = [x for x in list1 if x in list2]
d = [y for y in (list1+list2) if y not in c]
print(c)
print(d)
用普通的for循环来写
list1 = [1,3,65,2,7]
list2 = [3,2,5,4]
list3 = []
list4 = []
for i in list1:
for j in list2:
if i == j:
list3.append(i)
for b in (list1 + list2):
if b not in list3:
list4.append(b)
print(list3)
print(list4)