Skip to content

Commit

Permalink
Binary Search using Bisect Module
Browse files Browse the repository at this point in the history
  • Loading branch information
detel committed Aug 8, 2015
1 parent 9c6fed3 commit 3d72286
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Binary Search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from bisect import bisect_left

def binary_search(a, x, lo=0, hi=None):
hi = hi if hi is not None else len(a)
pos = bisect_left(a,x,lo,hi)
return (pos if pos != hi and a[pos] == x else -1)

0 comments on commit 3d72286

Please sign in to comment.