https://github.com/python/cpython/commit/22a123f1305bf45d5d35441e9164fb4528da493c
commit: 22a123f1305bf45d5d35441e9164fb4528da493c
branch: main
author: Dan Shernicoff <[email protected]>
committer: ZeroIntensity <[email protected]>
date: 2026-07-28T01:41:17Z
summary:
gh-154746: Update docstring for `collections.Counter` (GH-154792)
Added a note to `collections.Counter`'s docstring that initializing a `Counter`
from a `Mapping` or `Counter` will have different behaviour than initializing
from other `Iterable`s.
This behaviour was already documented in the canonical docs but is missing from
the help() output.
files:
M Lib/collections/__init__.py
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index 20f1e728733fec6..5dbcac19e7a9272 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -553,6 +553,9 @@ class Counter(dict):
or multiset. Elements are stored as dictionary keys and their counts
are stored as dictionary values.
+ When constructed from a Mapping or Counter, the original object's
+ values will be used as the initial counts.
+
>>> c = Counter('abcdeabcdabcaba') # count elements from a string
>>> c.most_common(3) # three most common elements
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]