加入收藏 | 设为首页 | 会员中心 | 我要投稿 北几岛 (https://www.beijidao.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

【小工具】1.需要对txt存放的测试数据做去重处理

发布时间:2021-05-21 04:57:20 所属栏目:大数据 来源: https://www.jb51.cc
导读:采用集合去重,在新文件里逐行写入,达成目的 old_file = "D:/testdata/memberId.txt" #oldresult_file = "D:/testdata/memberId_new.txt" #newlines_seen = set()out_file = open(result_file,"w")f = open(old_file,"r")for line in f: if line not in lin

采用集合去重,在新文件里逐行写入,达成目的


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")

(编辑:北几岛)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读