3 ms·
There are already multiline lambda functions available by using the walrus operator: foo = lambda x: ( z:=x+1, zz:=z*2, zz+7 )[-1] it defines a tuple and
by fxj 3y ago
There are already multiline lambda functions available by using the walrus operator:
foo = lambda x: ( z:=x+1, zz:=z*2, zz+7 )[-1]
it defines a tuple and returns the last element. List comprehensions, walrus operator and lambda make a functional language out of python.
- Jtsummers 3y agoAs written, your comment isn't demonstrating multiline lambdas. You need to prefix each of the code lines with two spaces so you get a code block. Otherwise it's treating it as a single paragraph and concatenating it all together. What you currently have: foo = lambda x: ( z:=x+1, zz:=z*2, zz+7 )[-1] What you seem to want: foo = lambda x: ( z:=x+1, zz:=z*2, zz+7 )[-1]