rot13 in a more Pythonic style?

tomtheisen@tomtheisen.com tom.theisen at gmail.com
Thu Feb 15 10:54:45 EST 2007


On Feb 14, 11:46 am, "Gabriel Genellina" <gagsl... at yahoo.com.ar>
wrote:
> En Wed, 14 Feb 2007 14:04:17 -0300, Andy Dingley <ding... at codesmiths.com>
> escribió:
>
> > I still don't understand what a lambda is _for_ in Python. I know what
> > they are, I know what the alternatives are, but I still haven't found
> > an instance where it permits something novel to be done that couldn't
> > be done otherwise (if maybe not so neatly).
>
> A lambda is a shorthand for a simple anonymous function. Any lambda can be
> written as a function:
>
> lambda args: expression
>
> is the same as:
>
> def __anonymous(args): return expression
>
> (but the inverse is not true; lambda only allows a single expression in
> the function body).
>
> Except for easy event binding in some GUIs, deferred argument evaluation,
> and maybe some other case, the're not used much anyway. Prior common usage
> with map and filter can be replaced by list comprehensions (a lot more
> clear, and perhaps as fast - any benchmark?)
>
> --
> Gabriel Genellina

They are still useful for reduce(), which has no listcomp equivalent
that I know of.




More information about the Python-list mailing list