[Python-Dev] Lambda [was Re: PEP 8 modernisation]
nd at perlig.de
Thu Aug 1 21:49:43 CEST 2013
* Stephen J. Turnbull wrote:
> Chris Angelico writes:
> > On Thu, Aug 1, 2013 at 5:58 PM, Alexander Shorin <kxepal at gmail.com>
> > > fun = lambda i: i
> > > for key, items in groupby(sorted(items, key=fun), key=fun):
> > > print(key, ':', list(items))
> > I'd do a direct translation to def here:
> > def fun(i): return i
> > for key, items in groupby(sorted(items, key=fun), key=fun):
> > print(key, ':', list(items))
> As long as it's about readability, why not make it readable?
> def second(pair): return pair
> for key, items in groupby(sorted(items, key=second), key=second):
> print(key, ':', list(items))
> I realize it's somewhat unfair (for several reasons) to compare that
> to Alexander's "fun = lambda i: i", but I can't help feeling that
> in another sense it is fair.
Seems to run OT somewhat, but "second" is probably a bad name here. If the
key changes, you have to rename it in several places (or worse, you DON'T
rename it, and then the readability is gone).
Usually I'm using a name with "key" in it - describing what it's for, not
how it's done. The minimal distance to its usage is supporting that, too.
"Das Verhalten von Gates hatte mir bewiesen, dass ich auf ihn und seine
beiden Gefährten nicht zu zählen brauchte" -- Karl May, "Winnetou III"
Im Westen was neues: <http://pub.perlig.de/books.html#apache2>
More information about the Python-Dev