s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
a=[]
if s1.isdisjoint(s2):
for x in s1:
for s in s2:
if s==x:
a.append(x)
print(a)
改成 if not s1.isdisjoint(s2):
set提供isdisjoint()方法,可以快速判断两个集合是否有重合,如果有重合,返回False,否则返回True
isdisjoint()