def index(self, value, start=0):
if self._isEmpty():
raise ValueError('OurList.index(x): x not in list')
elif start == 0 and self._head == value:
return 0
else:
return 1 + self._rest.index(value, max(start-1,0))
def search(lexicon, target):
return _search(lexicon, target, 0, len(target))
def _search(lexicon, target, start, stop):
if start >= stop:
return stop # if we didn't find item, must go between stop-1 and stop
else:
mid = (start+stop)//2
if target == lexicon[mid]:
return mid # that's where we found it
elif target < lexicon[mid]:
return _search(lexicon, target, start, mid)
else:
return _search(lexicon, target, mid+1, stop)