Looking at Python-Dev and StackOverflow, Python's ternary operator equivalent is:
a if condition else b
Looking at PEP-572 and StackOverflow, I understand what Walrus operator is:
:=
Now I'm trying to to combine the "walrus operator's assignment" and "ternary operator's conditional check" into a single statement, something like:
other_func(a) if (a := some_func(some_input)) else b
For example, please consider the below snippet:
do_something(list_of_roles) if list_of_roles := get_role_list(username) else "Role list is [] empty"
I'm failing to wrap my mind around the syntax. Having tried various combinations, every time the interpreter throws SyntaxError: invalid syntax
. My python version is 3.8.3.
My question is What is the correct syntax to embed walrus operator within ternary operator?