利用 Python3 找出缺席名單
f1 = open('111.txt', 'r') f2 = open('222.txt', 'r') #讀取 111.txt(點名名單) & 222.txt(修課名單) 進行比對 s1 = set(f1) s2 = set(f2) #將兩者集合 print ('二乙缺席名單:') print (list(s1.symmetric_difference(s2)))
顯示結果如下:
二乙缺席名單: ['40523224\n', '40523232\n', '40523212\n', '40523234\n', '40523227\n', '40523231\n', '40523217\n', '40523222\n']
參考資料:
Python3 字串型態
https://openhome.cc/Gossip/Python/StringType.html