slice - Splice list of date objects in Python -


is there simple way splice list of date objects:

spliced = sorteddates[startdate:enddate] print spliced 

or requires enumeration?

example:

sorteddates = [july 1 2012, july 2 2012, july 3 2012, july 4, 2012] spliced = sorteddates[july 2 2012:july 4 2012] 

assuming have list sorteddates contains datetime object, , 2 datetime mind , maxd objects define boundaries:

filtered = [d d in sorteddates if mind < d < maxd] 

or, more efficient since takes advantage of sorted nature of list use binary search:

from bisect import bisect_left, bisect_right filtered = sorteddates[bisect_right(sorteddates, mind):bisect_left(sorteddates, maxd)] 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -