forked from Jackevansevo/Udacity-Python-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
30 lines (21 loc) · 629 Bytes
/
index.py
File metadata and controls
30 lines (21 loc) · 629 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
# Define a procedure, lookup,
# that takes two inputs:
# - an index
# - keyword
# The procedure should return a list
# of the urls associated
# with the keyword. If the keyword
# is not in the index, the procedure
# should return an empty list.
index = [['udacity', ['http://udacity.com', 'http://npr.org']],
['computing', ['http://acm.org']]]
def lookup(index,keyword):
x = 0
for entry in index:
if entry[x] == keyword:
return entry[x+1]
return ("Entry not found")
print lookup(index,'udacity')
print lookup(index, 'computing')
print lookup(index, 'fobar')
#>>> ['http://udacity.com','http://npr.org']