-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck.py
63 lines (47 loc) · 1.19 KB
/
check.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
56
57
58
59
60
61
62
63
from datetime import date
fname1 = 'data/nouns.txt'
fname2 = 'data/russian_nouns_without_filter.txt'
fname_added = 'data/added.txt'
fout = 'data/nouns1.txt'
# * start
def parse_line(line):
(word, *description) = line.split(':')
return word
def read_file_lines(fname):
f = open(fname, 'r', encoding='utf-8')
data = f.readlines()
f.close()
return data
def load_added():
aa = []
for line in open(fname_added, 'r', encoding='utf-8'):
s = line.strip()
if s:
aa.append(s)
return aa
def write_file_lines(fname, data):
data1 = map(lambda v: v + '\n', data)
f = open(fname, 'w', encoding='utf-8')
f.writelines(data1)
f.close()
added = load_added()
data1 = read_file_lines(fname1)
data2 = read_file_lines(fname2)
data = []
iter2 = iter(data2)
for v in data1:
line = v.strip()
word = parse_line(line)
if word in added:
print(f"1a:{line}")
data.append(line)
continue
while True:
word2 = next(iter2).strip()
if word2 == word:
break
print(f"2:{word2}")
data.append(word2)
print(f"1:{line}")
data.append(line)
# write_file_lines(fout, data)