How to return False when using issubset and an empty set
<p>When I have two sets e.g.</p>

<pre><code>s1 = set()    
s2 = set(['somestring'])
</code></pre>

<p>and I do </p>

<pre><code>print s1.issubset(s2)
</code></pre>

<p>it returns <code>True</code>; so apparently, an empty set is always a subset of another set.</p>

<p>For my analysis, it should actually return <code>False</code> and I am wondering about the best way to do this. I can write a function like this:</p>

<pre><code>def check_set(s1, s2):
    if s1 and s1.issubset(s2):
        return True
    return False
</code></pre>

<p>which then indeed returns <code>False</code> for the example above. Is there any better way of doing this?</p>

<p>You can take advantage of how Python evaluates the truthiness of an object <strong>plus</strong> how it short-circuits boolean <code>and</code> expressions with:</p>

<pre><code>bool(s1) and s1 &lt;= s2
</code></pre>

<p>Essentially this means: if <code>s1</code> is something not empty AND it's a subset of <code>s2</code></p>

python optimization set