print('=============')
def readT(filename):
arr = ''
print('====================')
with open(filename,'r') as f_r:
lines = f_r.readline()
arr = lines.split(' ')
return arr
line_os = readT('lh.txt')
line_ts = readT('sh.txt')
#
#print(set(line_os) & set(line_ts))
#
lines = set(line_os) | set(line_ts)
print(lines)
line_txt = ' '.join(lines)
print(line_txt)
with open('pos.txt','w',encoding='utf-8') as f_w:
f_w.write(line_txt)
f_w.close()
#print(line_os)
#print('==================')
#print(line_ts)
扩展知识:
print set(a) & set(b) # 交集, 等价于set(a).intersection(set(b))
print set(a) | set(b) # 并集, 等价于set(a).union(set(b))
print set(a) - set(b) # 差集,在a中但不在b中的元素, 等价于set(a).difference(set(b))
print set(b) - set(a) # 差集,在b中但不在a中的元素, 等价于set(b).difference(set(a))