[Tutor] seek and slice a range in a list of dates

washakie washakie at gmail.com
Sun Feb 10 12:01:55 CET 2008


Yes, I'm using 2.4, and will not likely be able to upgrade... so, the final,
as you suggested Kent:

  
dates_dt=([datetime.datetime(int(dates_list[i][0][:4]),int(dates_list[i][0][4:6]),
                               
int(dates_list[i][0][6:8]),int(dates_list[i][0][8:10]),
                               
int(dates_list[i][0][10:12]),int(dates_list[i][0][12:]))
                                for i in range(len(dates_list))])     

   TstartNew=sorted(dates_dt,key=lambda d: abs(Tstart - d))[0]
   Tstart_i=dates_dt.index(TstartNew)
   TendNew=sorted(dates_dt, key=lambda d: abs(Tend -d))[0]
   Tend_i=dates_dt.index(TendNew)

This definitely seems to cleanest way... thank you! One question, how would
this handle duplicates in the dates_dt list?
-- 
View this message in context: http://www.nabble.com/seek-and-slice-a-range-in-a-list-of-dates-tp15389997p15395230.html
Sent from the Python - tutor mailing list archive at Nabble.com.



More information about the Tutor mailing list