-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearchEngine.py
More file actions
executable file
·33 lines (25 loc) · 861 Bytes
/
searchEngine.py
File metadata and controls
executable file
·33 lines (25 loc) · 861 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
index = []
def add_to_index(index, keyword, url):
for entry in index:
if entry[0] == keyword:
if url not in entry[1]:
entry[1].append(url)
return
index.append([keyword, [url]])
def lookup(index, keyword):
for entry in index:
if entry[0] == keyword:
return entry[1]
return []
def add_page_to_index(index, url, content):
keywords = content.split()
for word in keywords:
add_to_index(index, word, url)
# add_to_index(index, 'udacity', 'http://udacity.com')
# add_to_index(index, 'computing', 'http://acm.org')
# add_to_index(index, 'udacity', 'http://npr.org')
# print (index)
# print (lookup(index, 'udacity'))
# # add_page_to_index(index, 'fake.test', "this is a is test")
# # add_page_to_index(index, 'not.test', "this is not a test")
# # print (index)