為啥運行出來a是個空集
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)
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)
2022-12-06
舉報
2022-12-08
改成 if not?s1.isdisjoint(s2):
set提供
isdisjoint()
方法,可以快速判斷兩個集合是否有重合,如果有重合,返回False,否則返回True