有两个文本文件,里面存放的都是同一种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)