<p>我在读这篇文章真的很有帮助,所以请发到<a href="https://stackoverflow.com/questions/613183/sort-a-python-dictionary-by-value">sorting dictionaries</a>上。最流行的答案之一就是:</p>
<pre><code>sorted(dict1, key=dict1.get)
</code></pre>
<p>虽然这看起来工作得很好,但我没有得到<code>key=dict1.get</code>部分。在</p>
<p>这里<code>get</code>到底是什么,它做什么?在</p>
<p>我只熟悉使用<code>get('X')</code>从字典中提取X。。。
而且我在字典和stdtype的<a href="https://docs.python.org/2/library/stdtypes.html" rel="nofollow noreferrer">docs</a>中找不到任何东西,所以我非常感谢任何的指针!在</p>
<p>这里是<a href="https://docs.python.org/2/library/stdtypes.html" rel="nofollow noreferrer">they</a>对<code>get()</code>的看法,还是完全不同?
谢谢!在</p>
<blockquote>
<p>get(key[, default])
Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to None, so that this method never raises a KeyError</p>
</blockquote>