Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
6
Task/Binary-search/Python/binary-search-6.py
Normal file
6
Task/Binary-search/Python/binary-search-6.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from bisect import bisect_left
|
||||
|
||||
def binary_search(a, x, lo=0, hi=None): # can't use a to specify default for hi
|
||||
hi = hi if hi is not None else len(a) # hi defaults to len(a)
|
||||
pos = bisect_left(a,x,lo,hi) # find insertion position
|
||||
return (pos if pos != hi and a[pos] == x else -1) # don't walk off the end
|
||||
Loading…
Add table
Add a link
Reference in a new issue