Finding specific date ranges
kyosohma at gmail.com
kyosohma at gmail.com
Thu Sep 6 14:05:46 EDT 2007
On Sep 6, 12:41 pm, Tim Golden <t... at timgolden.me.uk> wrote:
> > Thanks! I'll try it both ways and see if there's any appreciable
> > difference in speed, although since it will be packaged into an
> > executable, that may not be an issue anyway.
>
> > Mike
>
> I honestly doubt there's any advantage to my approach, certainly
> not in terms of speed. It's really only if it happens to suit
> your mind better, or take advantage of structures you might
> already have in place, etc.
>
> TJG
For completeness, here's my method for comparison's sake:
<code>
date_list = [('12/31/2006', '01/13/2007'),
('01/14/2007', '01/27/2007'),
('01/28/2007', '02/10/2007'),
('02/11/2007', '02/24/2007'),
('02/25/2007', '03/10/2007'),
('03/11/2007', '03/24/2007'),
('03/25/2007', '04/07/2007'),
('04/08/2007', '04/21/2007'),
('04/22/2007', '05/05/2007'),
('05/06/2007', '05/19/2007'),
('05/20/2007', '06/02/2007'),
('06/03/2007', '06/16/2007'),
('06/17/2007', '06/30/2007')
]
vac_periods = []
found = False
for d in date_list:
begin = d[0][0:2]
end = d[1][0:2]
if begin == end and found == False:
vac_periods.append(d)
found = True
else:
found = False
print vac_periods
</code>
Isn't it kind of late in the day over there, Tim? Anyway, your method
is probably clearer to read whereas mine doesn't require anything to
be imported. I didn't even realize there was a calendar module...or
maybe I forgot about it.
Mike
More information about the Python-list
mailing list