What's a pythonic way to check membership in a list that could be None?
<p>I need to get all keys in a dictionary whose corresponding value is above a minimum and that are in a given list. Something like:</p>

<pre><code>result = [k for k in my_dict if my_dict[k] &gt; min_value and k in allowed_keys]
</code></pre>

<p>However, it may be the case that I have no restriction on allowed keys. I find that the most pythonic to do it is to set allowed_keys to None. But this would leave me with the ugly piece of code:</p>

<pre><code>if allowed_keys is None:
    result = [k for k in my_dict if my_dict[k] &gt; min_value]
else:
    result = [k for k in my_dict if my_dict[k] &gt; min_value and k in allowed_keys]
</code></pre>

<p>I feel like there must be a more sensible and pythonic solution. I thought of using a lambda function, but I'm not sure. Any ideas?</p>
