Re: find nearest time in datetime list

2008-01-30 Thread washakie
> > print sorted (dates, key=lambda x: abs (x-one_date))[0] > > > > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/find-nearest-time-in-datetime-list-tp15180398p15183205.html Sent f

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

find nearest time in datetime list

2008-01-30 Thread washakie
http://www.nabble.com/find-nearest-time-in-datetime-list-tp15180398p15180398.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list