A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-May/079130.html below:

[Python-Dev] PEP 8: Discourage named lambdas?

[Python-Dev] PEP 8: Discourage named lambdas?Alex Martelli aleaxit at gmail.com
Sun May 4 19:23:40 CEST 2008
On Sun, May 4, 2008 at 3:31 AM, Raymond Hettinger <python at rcn.com> wrote:
   ...
>   for k,g in groupby(iterable, key=lambda r: (r[0].lower(), r[5].lower())):
> ...
>     lastname_firstname = lambda r: (r[0].lower(), r[5].lower())
>   for k, g in groupby(iterable, key=lastname_firstname): ...
>
>  That transformation adds clarity.  Going further and creating a separate
>  def-statement outside the current function would just move the relevant
>  code farther away and impair readability.

And that would be totally silly and uncalled for -- why ever would it
be placed *outside the current function*?!  What a straw-man...!  Just
do

def last_first(r): return r[0].lower(), r[5].lower()
for k, g in groupby(iterable, key=last_first): ...

putting the def right where you now have the "<name> = lambda ..." of course!

Alex
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4