list - this simple function in python doesn't work properly -
i have problems these lines of program. i'm writing function in python takes list of lists , string input , returns "the name here" if second element of list in list of lists equal string given. in case list of list have
railway = [["milan","zurich"],["zurich","bern"],["bern","berlin"],["berlin","copenaghen"]]
my function is:
def travel( list , stringdestination): = 0 elemento in range(len(list)): if list[i][1] == stringdestination: print "target reached"
when run:
travel(railway, "bern")
it should display: "target reached" doesn't, doesn't show anything, why?
you never incrementing i. loop should be:
for pair in list: if pair[1] == stringdestination: print "target reached"
Comments
Post a Comment