python - Recursive code returns None -
i not understand, why code
def isin(char, astr): ms = len(astr)/2 if astr[ms] == char: print 'i here now' return true elif char>astr[ms] , not ms == len(astr)-1: astr = astr[ms+1:] elif char <astr[ms] , not ms == 0: astr = astr[0:ms] else: return false isin(char, astr) print isin('a', 'ab') does keep on returning none. prints 'i here now', not return true, next line says. why?
you want return on last line:
return isin(char, astr) without it, function returns none when terminates without seeing return.
Comments
Post a Comment