python ternary operator with assignment
<p>I am new to python. I'm trying to write this</p>

<pre><code>if x not in d:
    d[x] = {}
q = d[x]
</code></pre>

<p>in a more compact way using the ternary operator</p>

<pre><code>q = d[x] if x in d else (d[x] = {})
</code></pre>

<p>but this gives the syntax error. What am I missing?</p>
