Skip to content

Commit 2a9eb2e

Browse files
committed
gh-154746: Document internal order and display order
1 parent c7b9a13 commit 2a9eb2e

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Doc/library/collections.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,15 @@ For example::
268268
>>> c['sausage'] = 0 # counter entry with a zero count
269269
>>> del c['sausage'] # del actually removes the entry
270270

271+
Counters main insertion order internally but display from most common to
272+
least common when possible:
273+
274+
>>> c = Counter(a=1, b=2, c=3)
275+
>>> c # display most common to least
276+
Counter({'c': 3, 'b': 2, 'a': 1})
277+
>>> list(c.items()) # original insertion order
278+
[('a', 1), ('b', 2), ('c', 3)]
279+
271280
.. versionadded:: 3.1
272281

273282
.. versionchanged:: 3.7 As a :class:`dict` subclass, :class:`Counter`

0 commit comments

Comments
 (0)