Abstract and concrete syntax

George Sakkis gsakkis at rutgers.edu
Fri Jun 10 13:01:43 EDT 2005


"Kay Schluehr" wrote:

> > You can do stuff like this: lambda x: x and 2 or 3
>
> You can also do this
>
>    lambda x: {True:2,False:3}.get(bool(a))
>
> which is both beautiful and pythonic.
>
> Kay

Beauty is in the eye of the beholder, and the same holds for
'pythonicity'; IMO both are much less obvious than the if/then/else,
especially for a beginner or someone who has never seen these idioms
before. I personally don't find the (ab)use of dictionaries in this
case to be more beautiful or pythonic than the and/or idiom (not to
mention the runtime cost of building a new dictionary every time), but
YMMV.

George




More information about the Python-list mailing list