Ah! but are we sure that the max and min dates are actually in the list?
If there are 'missing dates' it might just be possible that it is the
max or min date that is missing.

On Fri, 09 Oct 2009 16:43 -0400, "Kent Johnson" <ken...@tds.net> wrote:
> On Fri, Oct 9, 2009 at 3:16 PM, Glen Zangirolami <digitalma...@gmail.com>
> wrote:
> > If i have a list of dates:
> > date_list =
> > ['2008-12-29','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-05']
> > How do I find the missing dates in the range of dates and insert them into
> > the list so I get?
> > date_list =
> > ['2008-12-29','2008-12-30','2008-12-31','2008-01-01','2008-01-02','2008-01-03','2008-12-04','2008-01-05']
> 
> I would do something like the following using datetime.datetime and
> datetime.timedelta:
> - convert each list item to a datetime object using datetime.strptime()
> - find the min and max datetimes in the list (use min() and max()
> - create a new list by incrementing the min date by timedelta(days=1)
> until it hits the max date
> - convert the new list to strings using datetime.strftime()
> 
> Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to