0
爲什麼第二個打印查找方法返回空白而不是鏈接acm.org?第一個結果是有道理的,但不應該第二個結果是相似的?無法理解python輸出
# 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 p in index:
if p[0] == keyword:
return p[1]
return []
print lookup(index,'udacity')
#>>> ['http://udacity.com','http://npr.org']
print lookup(index,'computing')
Results:
['http://udacity.com', 'http://npr.org']
[]
謝謝你..我是一個小菜鳥。下次會更加小心。 – algorythms