Solve a Debate

Steve Holden steve at holdenweb.com
Sun Feb 17 03:08:14 CET 2008


John Machin wrote:
> On Feb 17, 11:11 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
> wrote:
>> En Sat, 16 Feb 2008 19:43:37 -0200, John Machin <sjmac... at lexicon.net>
>> escribi�:
>>
>>> On Feb 16, 3:48 pm, Dan Bishop <danb... at yahoo.com> 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)?)
>>
> 
> Some people write such arcane expressions in Python solely for
> amusement in the newsgroup. I suggest that if you actually find any
> who write such expressions in Python *instead* of using a dictionary,
> you should don your nice red uniform and arraign them before the
> Inquisition forthwith.

Not the comfy chair!
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list