Group together arbitrary date objects that are within a time range of each other
I want to split the calendar into two-week intervals starting at 2008-May-5 , or any arbitrary starting point. So I start with several date objects: import datetime as DT raw = ("2010-08-01", "2010-06-25", "2010-07-01", "2010-07-08") transactions = [(DT.datetime.strptime(datestring, "%Y-%m-%d").date(), "Some data here") for datestring in raw] transactions.sort() By manually analyzing the dates, I am quite able to figure out which dates fall within the same fortnight interval. I want to get grouping that's similar to this one: # Fortnight interval 1 (datetime.date(2010, 6, 25), 'Some data here'