【小工具】1.需要对txt存放的测试数据做去重处理
作者:互联网
采用集合去重,在新文件里逐行写入,达成目的
old_file = "D:/testdata/memberId.txt" #old result_file = "D:/testdata/memberId_new.txt" #new lines_seen = set() out_file = open(result_file, "w") f = open(old_file, "r") for line in f: if line not in lines_seen: out_file.write(line) lines_seen.add(line) out_file.close() print("distinct_success")
标签:old,lines,测试数据,存放,file,seen,line,txt 来源: https://blog.51cto.com/u_13407532/2728309