Re: find nearest time in datetime list

2008-01-30 Thread washakie
Thanks all! This is terrific, and a quick response... I have to go with the 2.4 version, but thanks to everyone... Tim Golden-4 wrote: > > washakie wrote: >> Hello, >> >> I have a list of datetime objects: DTlist, I have another single datetime >> object: dt, ... I need to find the nearest DT

Re: find nearest time in datetime list

2008-01-30 Thread Tim Chase
Boris Borcic wrote: > min(DTlist,key=lambda date : abs(dt-date)) In Python2.4: Traceback (most recent call last): File "", line 1, in ? TypeError: min() takes no keyword arguments Looks like min() only started taking keywords (key) from Python2.5 forward. But the min() solution is g

Re: find nearest time in datetime list

2008-01-30 Thread Boris Borcic
washakie wrote: > Hello, > > I have a list of datetime objects: DTlist, I have another single datetime > object: dt, ... I need to find the nearest DTlist[i] to the dt is > there a simple way to do this? There isn't necessarily an exact match... > > Thanks! > .john > min(DTlist,key=lambd

Re: find nearest time in datetime list

2008-01-30 Thread Tim Chase
> I have a list of datetime objects: DTlist, I have another single datetime > object: dt, ... I need to find the nearest DTlist[i] to the dt is > there a simple way to do this? There isn't necessarily an exact match... import datetime dates = [datetime.datetime(2007,m, 1) for m in range(1,1

Re: find nearest time in datetime list

2008-01-30 Thread Tim Golden
washakie wrote: > Hello, > > I have a list of datetime objects: DTlist, I have another single datetime > object: dt, ... I need to find the nearest DTlist[i] to the dt is > there a simple way to do this? There isn't necessarily an exact match... import datetime dates = [datetime.date (20