Special keyword argument lambda syntax

Hrvoje Niksic hniksic at xemacs.org
Fri Mar 13 17:26:29 CET 2009


MRAB <google at mrabarnett.plus.com> writes:

>>>> sorted(range(9), def key(n): n % 3)
> [0, 3, 6, 1, 4, 7, 2, 5, 8]

Given the recent pattern of syntactic constructs for expressions using
<expr> <keyword> <expr> (ternary if, listcomps, genexps), and avoiding
the use of colon in expressions, maybe it should be:

sorted(range(9), key=n % 3 def key(n))

this is analogous to

sorted(range(9), foo=n % 3 if bla(n))

It also shares the property that it reuses an existing keyword and
avoids the word "lambda", originally (I presume) an homage to Church,
now considered obscure-sounding by many.



More information about the Python-list mailing list