Solve a Debate

John Machin sjmachin at lexicon.net
Sat Feb 16 20:33:20 EST 2008


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.



More information about the Python-list mailing list