On Mon, 24 Jul 2023 at 10:31, anthony.flury via Python-ideas < python-ideas@python.org> wrote:
> In Python then a better way might be > > result = temp := bar() if temp else default > > This way only bar() and default are evaluated and invoked once. > Or result = bar() if not result: result = default Seriously, what is the obsession with putting things on one line here? If it's because "it works better when there is a long list of such assignments" then unless you actually show a real-world example, it's hard to discuss the *actual* trade-offs. And typically with a real-world example, there are a lot more options available (for example, if this is defaulting a series of arguments to a function, it's often an anti-pattern to have a function with that many arguments in the first place, so refactoring the code may be a better option). Paul
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/7QE4CV2ZXNWAVFLVPXOYBB224447UFNL/ Code of Conduct: http://python.org/psf/codeofconduct/