python怎么合并运行条

更新时间:01-18 教程 由 昔日& 分享

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

声明:关于《python怎么合并运行条》以上内容仅供参考,若您的权利被侵害,请联系13825271@qq.com
本文网址:http://www.25820.com/tutorial/14_2182565.html