putting date strings in order

Scott David Daniels Scott.Daniels at Acm.Org
Thu May 14 22:13:09 CEST 2009


Peter Otten wrote:
> Hm, if ordered_raster_list is guaranteed to contain one string item for 
> every month the above can be simplified to
> 
> months = [
>     'precip_jan', 'precip_feb', 'precip_mar', 'precip_apr', 
>     'precip_may', 'precip_jun', 'precip_jul', 'precip_aug', 
>     'precip_sep', 'precip_oct', 'precip_nov', 'precip_dec']
> 
> start = 2
> ordered_raster_list = months[start-1:] + months[:start-1]

Or even:
 >
     multi_months = [
         'precip_jan', 'precip_feb', 'precip_mar', 'precip_apr',
         'precip_may', 'precip_jun', 'precip_jul', 'precip_aug',
         'precip_sep', 'precip_oct', 'precip_nov', 'precip_dec'] * 2
     start = 2
     ordered_raster_list = multi_months[start - 1: start + 11]

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list