Python workarounds for assignment in lambda
Assignment expressions in Python 3.8



Python 3.8 (TIO) introduces assignment expressions, which use := to assign a variable inline as part of expression.

&gt;&gt;&gt; (n:=2, n+1)
(2, 3)


This can be used inside a lambda, where assignments are not ordinarily allowed. Compare:

lambda s:(t:=s.strip())+t[::-1]
lambda s:s.strip()+s.strip()[::-1]
def f(s):t=s.strip();return t+t[::-1]


See this tip for more.