Full story
The final chop method I came up with was rather uninspired. I used a for loop instead a while loop and used some array manipulation.
Here’s the code:
def chopFive(value, list):
if len(list) == 0:
return -1
index = 0
newList = list
found = False
for number in range(0, len(list) / 2 + 1):
tempIndex = len(newList) / 2
if value == newList[tempIndex]:
return index + tempIndex
elif value > newList[tempIndex]:
newList = newList[tempIndex+1:len(newList)]
if len(newList) == 0:
return -1
index += tempIndex + 1
elif value < newList[tempIndex]:
newList = newList[0:tempIndex]
if len(newList) == 0:
return -1
return -1
No comment yet
Don't be shy, express yourself ! ;)