I have written a bisect function that takes a word list "t" and a word "val". It recursively halves the list until the index of the list is the word or returns false. If it finds the word, it is supposed to return it.
I have read multiple books, the documentation, and all the applicable questions here on SO but I still cannot determine what I am doing wrong: why won't the function return the value? It will print the value just fine, but no return except None.
Any help is greatly appreciated!
def bisect(t, val):
if t[len(t)/2] < val and len(t) > 1:
t = t[len(t)/2:]
bisect(t, val)
elif t[len(t)/2] > val and len(t) > 1:
t = t[:len(t)/2]
bisect(t, val)
elif t[len(t)/2] == val:
t = t[len(t)/2]
#print type(t), t
return t
else:
return False
b = make_list(t)
x = bisect(b, 'and')
print x
return bisect(..)when performing the recursive calls?ifand the firstelif, it prints the (half) list correctly until it finds the value. Am I understanding your question correctly?