-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathRemove_Duplicates.py
55 lines (28 loc) · 960 Bytes
/
Remove_Duplicates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#coding=utf-8
import sys, re, os
def getDictList(dict):
regx = '''[\w\~`\!\@\#\$\%\^\&\*\(\)\_\-\+\=\[\]\{\}\:\;\,\.\/\<\>\?]+'''
with open(dict) as f:
data = f.read()
return re.findall(regx, data)
def rmdp(dictList):
return list(set(dictList))
def fileSave(dictRmdp, out):
with open(out, 'a') as f:
for line in dictRmdp:
f.write(line + '\n')
def main():#用法是在命令行中执行Remove_Duplicates.py test.txt result.txt
try:
dict = sys.argv[1].strip()
out = sys.argv[2].strip()
except Exception, e:
print 'error:', e
me = os.path.basename(__file__)
print 'usage: %s <input> <output>' %me #被去重文本
print 'example: %s dict.txt dict_rmdp.txt' %me #去重后结果文本
exit()
dictList = getDictList(dict)
dictRmdp = rmdp(dictList)
fileSave(dictRmdp, out)
if __name__ == '__main__':
main()