On 2023-07-17 18:10, Dom Grigonis wrote:
It does exactly the same as the C version and is more readable. Or am
I missing something?
My point is exactly that it is not easily readable compared to C
version. Also, unnecessarily verbose. The order of components is rather
awkward.
I came to this, because people seem to want one-liners for certain
things and what I came up with is that maybe more concise if-else
expression could help.
# Fairly reasonable case.
def foo(a:bool, c:float, d:float)
val= a? (c? c : d) : (d? d : c)
return val
# Comapred to
def bar(a:bool, c:float, d:float)
val= (cif celse d)if aelse (dif delse c)
return val
Maybe for someone who majored in languages python’s if-else is more
easily understood. To me, personally, 2nd one is unbearable, while 1st
one is fairly pleasant and satisfying.
This whole thing started from dict’s `get` extension:
def get_substitute(self, key, default=None, subs=()):
return keyin self ? (self[key] := valin subs? subs[val] : val) :
default
I dare you to do a 1-liner with current if-else.
def get_substitute(self, key, default=None, subs=()):
return (self[key] := subs[val] if val in subs else val) if key in
self else default
Where does 'val' come from?
[snip]
_______________________________________________
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/ZSTKPJCB4TZCEE2UGPXT5QKLISGORPDK/
Code of Conduct: http://python.org/psf/codeofconduct/