diff options
author | Tim Peters <tim.peters@gmail.com> | 2006-06-02 23:22:51 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2006-06-02 23:22:51 (GMT) |
commit | d609b1a20e9cc100d2998e030ec88347b6943904 (patch) | |
tree | 1b21822316e37c0d09f0e5e1f64156e5a2bb1b4f /Lib/pprint.py | |
parent | 7f7386cfd2936a552d73fed2ddd12c5a54004034 (diff) | |
download | cpython-d609b1a20e9cc100d2998e030ec88347b6943904.zip cpython-d609b1a20e9cc100d2998e030ec88347b6943904.tar.gz cpython-d609b1a20e9cc100d2998e030ec88347b6943904.tar.bz2 |
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.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/pprint.py b/Lib/pprint.py index f77a0e2..19a3dc2 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)) |