擅长:python、mysql、java
<p>另一个好方法是使用<code>pprint</code>(在标准库中)。</p>
<pre><code>>>> import pprint
>>> pprint.pprint({"second": 1, "first": 0})
{'first': 0, 'second': 1}
</code></pre>
<p>根据它的源代码,它正在为您排序命令:</p>
<p><a href="http://hg.python.org/cpython/file/2.7/Lib/pprint.py#l158">http://hg.python.org/cpython/file/2.7/Lib/pprint.py#l158</a></p>
<pre><code>items = _sorted(object.items())
</code></pre>