有兩個文字檔案,裡面存放的都是同一種ID,內容如下:
a.txt:
175
200
100
b.txt:
100
73822
8888
ID號在各自檔案中唯一不重複,現在要找出所有隻出現在一個檔案中的ID,請用python實現
輸出順序無所謂:
175
100
200
73822
8888
python解:
with open(r'learn-python3\practice\a.txt','r') as a:
id_a = set(a.read().splitlines())
with open(r'learn-python3\practice\b.txt','r') as b:
id_b = set(b.read().splitlines())
id_set = set(list(id_a) + list(id_b))
for id in id_set:
print(id)