-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCoroutines_Exercise_SearchText.py
42 lines (37 loc) · 1.31 KB
/
Coroutines_Exercise_SearchText.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
# Challenge Answer on the topic Coroutines In Python
file_name_list = ["letter_1.txt","letter_2.txt","letter_3.txt","letter_4.txt","letter_5.txt",
"letter_6.txt","letter_7.txt","letter_8.txt","letter_9.txt","letter_10.txt"]
try:
def searchtext():
mydict = {}
for item in file_name_list:
mywords = ""
with open(item) as file:
contents = file.readlines()
for words in contents:
mywords = mywords + " " + words.replace("\n", "").lower()
mydict.update({item:mywords})
while True:
text = (yield)
for key, value in mydict.items():
if text in value:
print("Found in File: ", key)
break
else:
print("Not Found")
search = searchtext()
next(search)
print("Search Started...")
keyword = ""
while keyword is not 'exit':
keyword = input("Enter Keywords [Type exit to Quit] : ").lower()
if keyword == 'exit':
print("Thank you !!!")
break
else:
search.send(keyword)
search.close()
except FileNotFoundError as e:
print("File Not Found !!!")
except Exception as e:
print("Something wrong. !!! Please Check...")