wangzhibo
2023-07-25 2ccac51ebb1d41c4dd6d2e07f6eb34f75a03210c
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
 
#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
import sys
 
 
 
'''
 
在第一个文件的基础上,添加后续的全部不重复的2字词语。
 
'''
_list_unique = set()
_list_temp = set()
 
base_txt_file = sys.argv[1]
new_added_txt_file =sys.argv[2]
base_txt_file_with_added = sys.argv[3]
 
with open(base_txt_file, 'r', encoding='utf-8-sig') as f:
        for word in f.read().splitlines():
            _list_unique.add(word[0])
            _list_unique.add(word[1])
            _list_unique.add(word[2])
            _list_unique.add(word[3])
 
print(len(_list_unique))
with open(base_txt_file_with_added, 'w', encoding='utf-8') as final_f:
    with open(new_added_txt_file, 'r', encoding='utf-8-sig') as f:
        for word in f.read().splitlines():
            #print(word)
            if len(word) == 2:
                _list_temp = _list_unique.copy()
                _list_temp.add(word[0])
                _list_temp.add(word[1])
 
                if len(_list_temp) - len(_list_unique) == 2:
                    _list_unique.add(word[0])
                    _list_unique.add(word[1])
                    final_f.write(word)
                    final_f.write('\n')
            else:
                print(word)
                print(len(word))