Binning into timeslots - Is there a better way than using list comp?

Posted by flyingcrab on Stack Overflow See other posts from Stack Overflow or by flyingcrab
Published on 2010-06-10T22:46:03Z Indexed on 2010/06/10 23:33 UTC
Read the original article Hit count: 245

Filed under:

I have a dataset of events (tweets to be specific) that I am trying to bin / discretize. The following code seems to work fine so far (assuming 100 bins):

HOUR = timedelta(hours=1)
start = datetime.datetime(2009,01,01)
z = [dt + x*HOUR for x in xrange(1, 100)]

But then, I came across this fateful line at python docs 'This makes possible an idiom for clustering a data series into n-length groups using zip(*[iter(s)]*n)'. The zip idiom does indeed work - but I can't understand how (what is the * operator for instance?). How could I use to make my code prettier? I'm guessing this means I should make a generator / iterable for time that yields the time in graduations of an HOUR?

© Stack Overflow or respective owner

Related posts about python