Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement