En Sat, 16 Feb 2008 19:43:37 -0200, John Machin <[EMAIL PROTECTED]>  
escribi�:
> On Feb 16, 3:48 pm, Dan Bishop <[EMAIL PROTECTED]> wrote:
>>
>> days_in_month = lambda m: m - 2 and 30 + bool(1 << m & 5546) or 28
>
> Alternatively:
>
> days_in_month = lambda m: m - 2 and 31 - ((m + 9) % 12 % 5 % 2) or 28
>
> the guts of which is slightly more elegant than the ancient writing
> from which it was derived:
>
> MOD(MOD(MOD(M+9,12),5),2)

I wonder why one would write such arcane expressions [in Python] instead  
of using a small dictionary {1:31, 2:28, 3:31...} which is auto  
documented, obviously correct, several times faster, and provides input  
validation for free (days_in_month(13)?)

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to