title: What is the correct syntax for Walrus operator with ternary operator?
body: <p>Looking at <a href="https://mail.python.org/pipermail/python-dev/2005-September/056846.html" rel="noreferrer">Python-Dev</a> and <a href="https://stackoverflow.com/questions/394809/does-python-have-a-ternary-conditional-operator">StackOverflow</a>, Python's ternary operator equivalent is:</p>
  <pre><code>a if condition else b
  </code></pre>
  <p>Looking at <a href="https://www.python.org/dev/peps/pep-0572/" rel="noreferrer">PEP-572</a> and <a href="https://stackoverflow.com/questions/57309129/walrus-operator-example-in-pep572">StackOverflow</a>, I understand what Walrus operator is:</p>
  <pre><code>:=
  </code></pre>
  <p>Now I'm trying to to combine the &quot;walrus operator's assignment&quot; and &quot;ternary operator's conditional check&quot; into a single statement, something like:</p>
  <pre><code>other_func(a) if (a := some_func(some_input)) else b
  </code></pre>
  <p>For example, please consider the below snippet:</p>
  <pre><code>do_something(list_of_roles) if list_of_roles := get_role_list(username) else &quot;Role list is [] empty&quot;
  </code></pre>
  <p>I'm failing to wrap my mind around the syntax. Having tried various combinations, every time the interpreter throws <code>SyntaxError: invalid syntax</code>. My python version is 3.8.3.</p>
  <p>My question is <strong>What is the correct syntax to embed walrus operator within ternary operator?</strong></p>