Conditional Help in Python
<p>I needed some help in understanding the following code:</p>

<pre><code>nextState = ((nextx, nexty), self.corners) if self.currentPosition not in self.corners else ((nextx, nexty), tuple([i for i in self.corners if i != self.currentPosition]))
successors.append((nextState, action, 1))
</code></pre>

<p>Can someone show me what this conditional statement would look like in multiple lines rather than just a one line if statement?</p>

<p>As an <code>if</code> statement, this would be:</p>

<pre><code>if self.currentPosition not in self.corners:
    nextState = ((nextx, nexty), self.corners)
else:
    nextState = ((nextx, nexty), tuple([i for i in self.corners if i != self.currentPosition]))
successors.append((nextState, action, 1))
</code></pre>

<p>This is essentially Python's form of a <a href="https://docs.python.org/3/faq/programming.html#is-there-an-equivalent-of-c-s-ternary-operator" rel="nofollow">ternary operator</a>.</p>

python