Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> with the caveat of needing to have it all in a single expression (the same goes for lambda, actually).

one could use multiple expressions in lambda in (modern) Python



Do you mean using the walrus operator? Because unless I missed a recent PEP, I don't know of a way to do this without something hacky like that.


yes

x = 1 y = 2

q = list(map(lambda t: ( tx := tx, ty := ty, tx+ty )[-1], [1, 2, 3]))

print(q)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: