-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython problem 7.py
More file actions
52 lines (41 loc) · 1.13 KB
/
python problem 7.py
File metadata and controls
52 lines (41 loc) · 1.13 KB
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
'''Author = Nitesh
Date = 14 May 2021
Topic = Create a local search engine
'''
sentences = ["this is good", "python is good",
"python is not python snake", "Rohan is a python developer"]
# empty list filled during process
dict1 = {}
l = []
keys = []
storage = []
s = 1
# query taken from the user
query = (input("Please input your query string:\n").lower()).split(' ')
# adding data in dictionary
for i in query:
for j in sentences:
if i in j.lower():
matches = j.count(i)
if j in dict1:
found = dict1[j]+matches
dict1[j] = found
else:
dict1[j] = matches
# adding data to list
for x in dict1:
l.append(dict1[x])
keys.append(x)
# apstracting data from list and dict
print(f"\n{len(keys)} results found:\n")
for t in range(len(keys)):
max_value = max(l)
for y in keys:
if dict1[y] == max_value:
if y not in storage:
storage.append(y)
print(f"{s}. {y}")
s += 1
l.remove(max_value)
if len(keys) == 0:
print('sorry! your query not found')