python怎么合并運行條?
# read data from file
with open("data_src.txt", 'rt') as src:
data = [ln.strip() for ln in src]
# distinct data and write to file with ', ' join
with open("data_sto.txt", 'wt') as sto:
sto.write(', '.join(list(set(data)))) python 中 set 是 “unordered collection of unique elements” 可以自動實現剔除重復數據。