]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-154746: Update docstring for `collections.Counter` (GH-154792)
authorDan Shernicoff <dan@brassnet.biz>
Tue, 28 Jul 2026 01:41:17 +0000 (21:41 -0400)
committerGitHub <noreply@github.com>
Tue, 28 Jul 2026 01:41:17 +0000 (01:41 +0000)
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.

Lib/collections/__init__.py

index 20f1e728733fec6662135caeeaa6e1966cad09de..5dbcac19e7a92726fb9594f406177870db1c08bd 100644 (file)
@@ -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