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


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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2021-07-20
  • 2022-12-23
  • 2021-07-20
  • 2021-04-08
猜你喜欢
  • 2021-07-26
  • 2022-12-23
  • 2021-11-10
  • 2021-10-04
  • 2022-12-23
  • 2021-07-22
  • 2021-12-19
相关资源
相似解决方案