集合间的运算
lst1 = [1, 2, 3, 5, 6, 3, 2]
lst2 = [2, 5, 7, 9]
虽然题目问的是两个列表之间的问题,但是用列表解答的效率很低,所以应该用集合
lst1 = [1, 2, 3, 5, 6, 3, 2]
lst2 = [2, 5, 7, 9]
set1 = set(lst1)
set2 = set(lst2)
# 哪些整数既在lst1中,也在lst2中
print(set1.intersection(set2))
# 哪些整数在lst1中,不在lst2中
print(set1.difference(set2))
# 两个列表⼀共有哪些整数
print(set1.union(set2)