From 2a9eb2eb6fd69f77d08b01727bc88c5cc628d2c1 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 27 Jul 2026 09:38:37 -0500 Subject: [PATCH 1/2] gh-154746: Document internal order and display order --- Doc/library/collections.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index d09a6c92bbd37dc..0da819b5b6af92d 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -268,6 +268,15 @@ For example:: >>> c['sausage'] = 0 # counter entry with a zero count >>> del c['sausage'] # del actually removes the entry + Counters main insertion order internally but display from most common to + least common when possible: + + >>> c = Counter(a=1, b=2, c=3) + >>> c # display most common to least + Counter({'c': 3, 'b': 2, 'a': 1}) + >>> list(c.items()) # original insertion order + [('a', 1), ('b', 2), ('c', 3)] + .. versionadded:: 3.1 .. versionchanged:: 3.7 As a :class:`dict` subclass, :class:`Counter` From 89dbc7b40c354c25138c6f3f129b01fa08d68b83 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 27 Jul 2026 11:27:44 -0500 Subject: [PATCH 2/2] Update Doc/library/collections.rst Co-authored-by: Stan Ulbrych --- Doc/library/collections.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 0da819b5b6af92d..599a898eb2cef83 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -268,7 +268,7 @@ For example:: >>> c['sausage'] = 0 # counter entry with a zero count >>> del c['sausage'] # del actually removes the entry - Counters main insertion order internally but display from most common to + Counters maintain insertion order internally but display from most common to least common when possible: >>> c = Counter(a=1, b=2, c=3)