Created
January 2, 2017 01:42
-
-
Save jesuscast/a5ca7cba259b55a71e4b651a3593b9fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def binarySearch(alist, item): | |
first = 0 | |
last = len(alist)-1 | |
index = None | |
while first<=last and not index: | |
midpoint = (first + last)//2 | |
if alist[midpoint] >= item: | |
index = midpoint | |
else: | |
if item < alist[midpoint]: | |
last = midpoint-1 | |
else: | |
first = midpoint+1 | |
return index | |
def searchDateRange(data, initialDate, finalDate): | |
i = binarySearch(data, initialDate) | |
if not i: | |
print "Could not find lower bound." | |
newArray = data[i:len(data)] | |
j = binarySearch(newArray, finalDate) | |
if not j: | |
print "Could not find lower bound" | |
return data[i:j] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment