diff --git a/IPython/lib/pretty.py b/IPython/lib/pretty.py index f7feff9..546446e 100644 --- a/IPython/lib/pretty.py +++ b/IPython/lib/pretty.py @@ -918,7 +918,7 @@ def _counter_pprint(obj, p, cycle): if cycle: p.pretty(cls_ctor(RawText("..."))) elif len(obj): - p.pretty(cls_ctor(dict(obj))) + p.pretty(cls_ctor(dict(sorted(obj.items(), key=lambda x: x[1], reverse=True)))) else: p.pretty(cls_ctor()) diff --git a/IPython/lib/tests/test_pretty.py b/IPython/lib/tests/test_pretty.py index 2d320bf..4cafc45 100644 --- a/IPython/lib/tests/test_pretty.py +++ b/IPython/lib/tests/test_pretty.py @@ -422,6 +422,7 @@ def test_collections_counter(): (Counter(), 'Counter()'), (Counter(a=1), "Counter({'a': 1})"), (MyCounter(a=1), "MyCounter({'a': 1})"), + (Counter(a=1, c=22), "Counter({'c': 22, 'a': 1})") ] for obj, expected in cases: assert pretty.pretty(obj) == expected