Python return False if list is empty
<p>In one coding example i saw the following code snippet that returns <strong>True</strong> if the list is empty and <strong>False</strong> if not</p>

<pre><code>return a == []
</code></pre>

<p>the reason for that is to avoid writing</p>

<pre><code>if a:
    return False
else:
    return True
</code></pre>

<p>In a real example with multiple thousands of entries, is there any speed difference i should be aware of?</p>

<p>No. There is no speed difference in either case. Since in both cases the <code>length</code> of the list is checked first.
In the first case, the <code>len</code> of <code>a</code> is compared with the <code>len</code> of <code>[]</code> before any further comparison. Most times the <code>len</code> should differ, so the test just returns immediately.</p>

<p>But the more pythonic way would be to just <code>return not a</code> or convert it using <code>bool</code> and then return it:</p>

<pre><code>return not a

# or 

return not bool(a)
</code></pre>

python