Syntax for one-line "nonymous" functions in "declaration style"

Antoon Pardon antoon.pardon at vub.be
Thu Mar 28 04:28:40 EDT 2019


On 27/03/19 22:25, Terry Reedy wrote:
> ...
>
> Before 3.8, I would stop here and say no to the proposal.  But we now
> have assignment expressions in addition to assignment statements.
>
> >>> int(s:='42'+'742')
> 42742
> >>> s
> '42742'
>
> To me, function assignment expressions, as a enhanced replacement for
> lambda expressions, is more inviting than function assignment
> statements as an abbreviation for function definition statements.
>
> In other words, replace
>
>   map(lambda x: x*x, range(10))
>
> with
>
>   map(square(x):=x*x, range(10))
>
> or, if one does not want a specific name,
>
>   map(_(x):=x*x, range(10))
>
> Many people dislike lambda expressions, to the point that Guido
> considered leaving them out of 3.x.  So this replacement might get
> more traction.  It would make assignment expressions much more useful.

I think map is not a good example, since I would just replace them with 
Since we are talking python 3.8 why not just use a generator here: (x*x for x in range(10))
instead of map? 




More information about the Python-list mailing list