Created
April 9, 2019 15:21
-
-
Save Warm-rain/f6af566e4525b283b6bf94739c48146e to your computer and use it in GitHub Desktop.
txt文本内容快速去重
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```python | |
# coding:utf-8 | |
import shutil | |
a=0 | |
readDir = "F:\\ipt.txt" #old | |
writeDir = "F:\\ipt1.txt" #new | |
# txtDir = "/home/fuxueping/Desktop/1" | |
lines_seen = set() | |
outfile = open(writeDir, "w", encoding='UTF-8') | |
f = open(readDir, "r", encoding='UTF-8') | |
for line in f: | |
if line not in lines_seen: | |
a+=1 | |
outfile.write(line) | |
lines_seen.add(line) | |
print(a) | |
print('\n') | |
outfile.close() | |
print("success") | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment