4 ms·
I would still prefer having a multiline lambda. We have this: def f(x): y = foo(x) z = bar(y) // ... return x some_obj.do_later
by gnulinux 6y ago
I would still prefer having a multiline lambda. We have this:
def f(x):
y = foo(x)
z = bar(y)
// ...
return x
some_obj.do_later(t, f, a, b, c)
I would prefer:
some_obj.do_later(t, lambda x: {
y = foo(x)
z = bar(y)
// ...
return x
}, a, b, c)
Maybe ( instead of {? I'm not sure that's possible to parse. Regardless, something like this would be good.
- OJFord 6y agoYes, I have wanted that before, and it could use existing valid syntax: some_obj.do_later(t, (lambda x: # (presently only a single non-comment line would be valid) x ), a, b, c)
- deleted 6y ago[deleted]
- contravariant 6y agoI suppose lambdas are already a bit weird for ending with a : without starting a new code block. Good luck fixing that though.
- cwhy 6y agoIn Python people are encouraged to follow styles for code as a communication tool between developers. If you just really want your code to "look nice" you can have things like this: def begin(*args): return args[-1] begin( func := lambda x, y: begin( z := int(input()), x + y + z ), func(1, 2) ) from `https://news.ycombinator.com/item?id=23346534 https://news.ycombinator.com/item?id=23346534`