# 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):
for entry in index:
if entry[0] is keyword:
return entry[1]
return []
print lookup(index,'udacity')
#>>> ['http://udacity.com','http://npr.org']
Created
July 17, 2016 01:00
-
-
Save babjo/6dafbd642a644fac90ea88ea9f215dad to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment