Warum gibt die zweite Druck-Lookup-Methode ein Leerzeichen zurück und nicht den Link acm.org? Das erste Ergebnis ist sinnvoll, aber sollte das zweite Ergebnis nicht ähnlich sein?Probleme beim Verständnis der Python-Ausgabe
# 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']
[]
danke..ich bin so ein Noob. Werde beim nächsten Mal vorsichtiger sein. – algorythms