なぜ、2番目の印刷参照メソッドが空白を返し、リンクacm.orgを返しませんか?最初の結果は理にかなっていますが、2番目の結果は似ていませんか?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