求差:
- method one:
list_one = [1, 2, 3] listd_two = [2, 3] diff = [] for x in list_one: if x not in list_two: diff.append(x)
- method two:
diff = [x for x in list_one if x not in list_two]
- method three:
diff = list(set(list_one)^set(list_two))
- method four:
diff = list(set(list_one).difference(set(list_two))) one中有而two中没有的
求和:
tt = list(set(list_one).union(set(list_two)))
求交:
for x in list_one:
if x in list_two:
jj.append(x)