Last active
January 2, 2017 01:44
-
-
Save jesuscast/31726912fd581f0754a3702961221cbe 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." | |
return None | |
newArray = data[i:len(data)] | |
j = binarySearch(newArray, finalDate) | |
if not j: | |
print "Could not find upper bound" | |
return None | |
return data[i:j] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment