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
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
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
> 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
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