Created
November 30, 2015 13:15
-
-
Save sodre/cb0a0fb38623ad8f00ef to your computer and use it in GitHub Desktop.
The start of a cartesian job runner.
This file contains 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 partition(start, end, step): | |
''' | |
Partitions the interval [start, end) into 'k' intervals [a_i, a_{i+1}). | |
''' | |
from itertools import takewhile, chain, islice, tee | |
# itertools.count does not work with datetime. | |
def count(firstval=0, step=1): | |
x = firstval | |
while 1: | |
yield x | |
x += step | |
assert(start_date < end_date) | |
a_i = takewhile(lambda x: x < end, count(start, step)) | |
a_i = tee(a_i) | |
a_ip1 = chain(islice(a_i[0], 1, None), [end]) | |
return zip(a_i[1], a_ip1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage