summaryrefslogtreecommitdiff
path: root/Lib/pprint.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2006-06-02 23:22:51 +0000
committerTim Peters <tim.peters@gmail.com>2006-06-02 23:22:51 +0000
commit5672d9ddac3be00f1820784c0ea067cf0c655e01 (patch)
tree03904e2918608190d5e3f4e2cce04601553b5f26 /Lib/pprint.py
parent297dfb876535d72100e5d096feb3d78b23115016 (diff)
downloadcpython-5672d9ddac3be00f1820784c0ea067cf0c655e01.tar.gz
pprint functions used to sort a dict (by key) if and only if
the output required more than one line. "Small" dicts got displayed in seemingly random order (the hash-induced order produced by dict.__repr__). None of this was documented. Now pprint functions always sort dicts by key, and the docs promise it. This was proposed and agreed to during the PyCon 2006 core sprint -- I just didn't have time for it before now.
Diffstat (limited to 'Lib/pprint.py')
-rw-r--r--Lib/pprint.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/pprint.py b/Lib/pprint.py
index f77a0e2248..19a3dc249c 100644
--- a/Lib/pprint.py
+++ b/Lib/pprint.py
@@ -246,7 +246,7 @@ def _safe_repr(object, context, maxlevels, level):
append = components.append
level += 1
saferepr = _safe_repr
- for k, v in object.iteritems():
+ for k, v in sorted(object.items()):
krepr, kreadable, krecur = saferepr(k, context, maxlevels, level)
vrepr, vreadable, vrecur = saferepr(v, context, maxlevels, level)
append("%s: %s" % (krepr, vrepr))