[Python-Dev] PEP 8: Discourage named lambdas? (original) (raw)
Greg Ewing greg.ewing at canterbury.ac.nz
Mon May 5 02:59:36 CEST 2008
- Previous message: [Python-Dev] PEP 8: Discourage named lambdas?
- Next message: [Python-Dev] AST Optimization: Branch Elimination in Generator Functions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Raymond Hettinger wrote:
lastnamefirstname = lambda r: (r[0].lower(), r[5].lower()) for k, g in groupby(iterable, key=lastnamefirstname): ...
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.
It doesn't have to be outside the function -- it can be in exactly the same place as the lambda assignment above.
def lastname_firstname(r): return (r[0].lower(), r[5].lower()) for k, g in groupby(iterable, key=lastname_firstname): ...
Maybe "def is an executable statement" is another thing people have a blind spot about?
-- Greg
- Previous message: [Python-Dev] PEP 8: Discourage named lambdas?
- Next message: [Python-Dev] AST Optimization: Branch Elimination in Generator Functions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]