
Ed K. answered 05/17/18
Tutor
4.8
(170)
Helpful Python tutor with a PhD and a passion for the language
I'm sure it's been proposed, but the short answer is that it would probably be kind of ugly. If you're assigning things, you've got at least two statements -- one to assign the variable and one to use it. It's tough for me to imagine needing to do an assignment unless you're going to immediately use that variable a number of times, so in practice your lambda is going to be really complex. But lambdas are so convenient because you can use them as function arguments, returns, yields, etc. in a very "lightweight" way. They're very minimal syntax, so the syntax doesn't get in the way. If your function isn't amenable to that, there's no reason to cram a lot of stuff onto one line, you can always just define a local function, possibly with only two lines, right before you need to use it, and pass it by name. That spreads out the code a bit and gives you a chance to comment and so forth.