Skip to content

Instantly share code, notes, and snippets.

@Warm-rain
Created April 9, 2019 15:21
Show Gist options
  • Save Warm-rain/f6af566e4525b283b6bf94739c48146e to your computer and use it in GitHub Desktop.
Save Warm-rain/f6af566e4525b283b6bf94739c48146e to your computer and use it in GitHub Desktop.
txt文本内容快速去重
```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