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” 可以自动实现剔除重复数据。