<blockquote>
<p><strong>Possible Duplicate:</strong><br/>
<a href="https://stackoverflow.com/questions/8287000/get-first-n-key-pairs-from-an-ordered-dictionary-to-another-one-in-python">Get first N key pairs from an Ordered Dictionary to another one in python</a> </p>
</blockquote>
<p>我有一本大词典。如何按降序对这些条目排序,然后打印前n个条目?要打印字典中已排序的项目,我使用以下代码:</p>
<pre><code>print sorted(mydictionary.iteritems(), key=operator.itemgetter(1), reverse=True)
</code></pre>