<p>从python文档中:</p>
<blockquote>
<p>A dictionary’s keys are almost
arbitrary values. Values that are not
hashable, that is, values containing
lists, dictionaries or other mutable
types (that are compared by value
rather than by object identity) may
not be used as keys.</p>
</blockquote>
<p><a href="http://docs.python.org/glossary.html#term-hashable" rel="noreferrer">Hashable</a>定义如下</p>
<blockquote>
<p>An object is hashable if it has a hash
value which never changes during its
lifetime (it needs a <code>__hash__()</code>
method), and can be compared to other
objects (it needs an <code>__eq__()</code> or
<code>__cmp__()</code> method). Hashable objects which compare equal must have the same
hash value.</p>
<p>Hashability makes an object usable as
a dictionary key and a set member,
because these data structures use the
hash value internally.</p>
</blockquote>
<p>因此,如果您想这样做,您需要重写对象上的默认<code>__hash__()</code>方法(请参阅下面史蒂文·伦巴尔斯基的注释以获得进一步的解释)。</p>
<hr/>
<pre><code>>>> content_type in package_disseminators.keys()
True
</code></pre>
<p>我想这是可行的,因为<code>dict.keys()</code>返回一个列表,并且<code>__contains__</code>可能检查等式,但不检查相同的散列。</p>