-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path8-compare_with_others.py
49 lines (35 loc) · 1.32 KB
/
8-compare_with_others.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
with open('finals.txt', 'r' , encoding='utf-8') as finals_file:
finals_lines = finals_file.readlines()
with open('allseed.txt', 'r', encoding='utf-8') as allseed_file:
allseed_lines = allseed_file.readlines()
newf = []
for line in finals_lines:
line = line.strip()
keep_line = True
for allseed_line in allseed_lines:
allseed_line = allseed_line.strip()
if line == allseed_line:
keep_line = False
break
if line[:4] == allseed_line[:4]:
keep_line = False
break
if len(line) == 3 and len(allseed_line) >= 4 and line == allseed_line[:3]:
keep_line = True
break
if len(allseed_line) < 3:
continue
if keep_line:
newf.append(line)
with open('finals.txt', 'r', encoding='utf-8') as finals_file:
finals_lines = finals_file.readlines()
with open('allseed.txt', 'r', encoding='utf-8') as allseed_file:
allseed_lines = allseed_file.readlines()
allseed_set = set(line.strip() for line in allseed_lines)
newf = []
for line in finals_lines:
if line.strip() not in allseed_set:
newf.append(line.strip())
with open('finals.txt', 'w', encoding='utf-8') as finals_file:
finals_file.write('\n'.join(newf))
print("Keep it cool!")