利用 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

Python3 集合set說明

http://www.iplaypy.com/jichu/set.html

Python3 輸出與輸入

http://docspy3zh.readthedocs.io/en/latest/tutorial/inputoutput.html

差集、相對差集、絕對差集

https://zh.wikipedia.org/wiki/%E8%A1%A5%E9%9B%86

比較兩者字串

http://wiki.alarmchang.com/index.php?title=%E6%AF%94%E8%BC%83%E5%85%A9%E5%80%8B_List_%E4%B9%8B%E9%96%93%E7%9A%84%E5%B7%AE%E7%95%B0