I am new into python and i am trying to implement binary search via recursion , I could see the solution of internet but i tried all way myself because i wanted to learn , so this is my approach :
y=7
count=0
def hello(x):
while len(x)>0:
for i in x:
a=len(x)//2
if y<x[a]:
print("left_most_side", a)
return hello(x[:a])
elif y==x[a]:
print("middle", a)
return a
elif y>x[a]:
print("right_most_side", a)
return hello(x[a:])
return x
hello([1,2,3,4,5,6,7])
Its working perfects and giving the output as expected but issue is , its printing the index of bi-sectioned list, while i need the index of origional list. example : a=[1,2,3,4] it bisection this and now [1,2] and [3,4] and now if i had to find 4 then it will print 4 is at position 0 , answer is correct but only in bisectioned list , while the correct answer is "4" is in origional list at position 3 so it should print 3 , that's the problem i am facing.
left, andrightparameter.