Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. def partition(start, end, step):
  2. '''
  3. Partitions the interval [start, end) into 'k' intervals [a_i, a_{i+1}).
  4. '''
  5. from itertools import takewhile, chain, islice, tee
  6.  
  7. # itertools.count does not work with datetime.
  8. def count(firstval=0, step=1):
  9. x = firstval
  10. while 1:
  11. yield x
  12. x += step
  13.  
  14. assert(start_date < end_date)
  15.  
  16. a_i = takewhile(lambda x: x < end, count(start, step))
  17. a_i = tee(a_i)
  18. a_ip1 = chain(islice(a_i[0], 1, None), [end])
  19. return zip(a_i[1], a_ip1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement