add
wangzhibo
2023-07-26 87d63066a319ea3d50ba9a39ee4d4e9967bca83f
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
 
#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
import sys
from numpy import *
 
'''
把原始的txt文件, 去重保存成新文件。
 
去重规格: 选取四个字中完全不重复的词语,比如“万马奔腾”,删除“鼎鼎有名”,“兢兢业业”,“打探打探”,“不干不净”等。
 
'''
 
base_txt_file = sys.argv[1]
exclude_duplicated = sys.argv[2]
 
 
with open(exclude_duplicated, 'w', encoding='utf-8') as final_f:
    with open(base_txt_file, 'r', encoding='utf-8-sig') as f:
        for word in f.read().splitlines():
            #print(word)
            if len(word) == 4:
                _list_unique = set()
                _list_unique.add(word[0]) 
                _list_unique.add(word[1]) 
                _list_unique.add(word[2]) 
                _list_unique.add(word[3]) 
                if len(_list_unique)  == 4:
                    final_f.write(word)
                    final_f.write('\n')
                else:
                    print(word)
            else:
                print(word)