python对txt文档内容去除重复行

xiaoxiao2025-06-06  42

import shutil readPath='cnews.test1.txt' writePath='cnews.test2.txt' lines_seen=set() outfiile=open(writePath,'a+',encoding='utf-8') f=open(readPath,'r',encoding='utf-8') for line in f: if line not in lines_seen: outfiile.write(line) lines_seen.add(line)

 

转载请注明原文地址: https://www.6miu.com/read-5031364.html

最新回复(0)