2 ms·
> There is no procedural concepts like variable assignment allowed in a python lambda. Just a small note that the walrus operator gives you some wiggle room he
by keithasaurus 5y ago
> There is no procedural concepts like variable assignment allowed in a python lambda.
Just a small note that the walrus operator gives you some wiggle room here:
add_5_to_square_if_greater_than_10 = lambda x: squared + 5 if (squared := x * x) > 10 else x
assert add_5_to_square_if_greater_than_10(2) == 2
assert add_5_to_square_if_greater_than_10(5) == 30
- deltaonefour 5y agoyeah my bad. Not fully up to date with all the newer python 3 tricks. That walrus operator is a trap though imo.