擅长:python、mysql、java
<p>因为默认情况下,<code>defaultdict</code>会将丢失的键添加到字典中,如<a href="http://hg.python.org/cpython/file/37ebb0d44808/Modules/_collectionsmodule.c#l1396" rel="nofollow">source</a>中所示。在</p>
<p>这种行为也记录在<a href="https://docs.python.org/2/library/collections.html#collections.defaultdict.__missing__" rel="nofollow">docs</a>:</p>
<blockquote>
<blockquote>
<blockquote>
<p>If default_factory is not None, it is called without arguments to provide a default value for the given key, this value is inserted in the dictionary for the key, and returned.</p>
</blockquote>
</blockquote>
</blockquote>