Binary Search Iterative method in python

This is an iterative method for the binary search algorithm. It takes a list as an input and another variable which is the data to be searched, and then passes them to the bin() function. And in bin() there is a single while loop.

Screenshots/ Output :

The Code

def bin(x,y):
l=0;
h=len(x)-1;
while(l<=h):
mid=(l+h)/2
if(x[mid]<y):
l=mid+1
elif(x[mid]>y):
h=mid-1
elif(x[mid]==y):
print "found "
break;
else:
print "Not Found "
x=input()
y=input()
bin(x,y);
Bikash Panda
Catch Me On

Bikash Panda

Blogger / Embedded System Developer at WeArGenius
A techie, tinkerer and tech lover, who loves to blog and feels everyone can learn tech provided they have the right attitude towards learning and passion. By profession, I am an IOT developer working in Smart Home/ Smart Grid domain.
Bikash Panda
Catch Me On

Latest posts by Bikash Panda (see all)

Bikash Panda

A techie, tinkerer and tech lover, who loves to blog and feels everyone can learn tech provided they have the right attitude towards learning and passion. By profession, I am an IOT developer working in Smart Home/ Smart Grid domain.