forked from python/python-docs-es
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_dict.py
More file actions
37 lines (30 loc) · 1002 Bytes
/
create_dict.py
File metadata and controls
37 lines (30 loc) · 1002 Bytes
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
from pathlib import Path
"""
Script to generate the 'dict.txt' dictionary based
on the custom dictionaries under the 'dictionaries/' directory,
but also considering the old words from the 'dict' file.
This was done with:
awk 1 dict dictionaries/*.txt > dict.txt
but the problem was that windows users, not using Git bash
have the problem that 'awk' is not a valid command, so this
enable them to use the script instead.
"""
entries = set()
# Read custom dictionaries
for filename in Path("dictionaries").glob("*.txt"):
with open(filename, "r") as f:
lines = [i.rstrip() for i in f.readlines()]
if lines:
entries.update(set(lines))
del lines
# Remove empty string, from empty lines
entries.remove("")
# Read main 'dict'
with open("dict", "r") as f:
entries.update(set(i.rstrip() for i in f.readlines()))
# Write the 'dict.txt' file
with open("dict.txt", "w") as f:
for e in entries:
f.write(e)
f.write("\n")
print("Created 'dict.txt'")