-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (30 loc) · 827 Bytes
/
main.py
File metadata and controls
42 lines (30 loc) · 827 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
38
39
40
41
42
import sys
import string
from multiprocessing import Pool
def file_read(path: str) -> str:
f = open(path, "r", encoding="utf-8")
text = f.read()
f.close()
return text
def text_fix(text: str) -> list:
text = text.translate(str.maketrans('', '', string.punctuation))
text = text.split()
return text
def search(key: str, path: str) -> None:
text = file_read(path)
text = text_fix(text)
if key in text:
print(f'"{key}" найден в {path}')
else:
print(f'"{key}" не найден в {path}')
return None
def main() -> None:
data = sys.argv[1:]
key = data[0].lower()
paths = data[1:]
key = [key] * len(paths)
with Pool(4) as p:
p.starmap(search, zip(key, paths))
return None
if __name__ == "__main__":
main()