From 24d46bb5c26eb6963476ccce7269adedf02c851e Mon Sep 17 00:00:00 2001 From: Dan Shernicoff Date: Mon, 27 Jul 2026 21:41:17 -0400 Subject: [PATCH] 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. (cherry picked from commit 22a123f1305bf45d5d35441e9164fb4528da493c) Co-authored-by: Dan Shernicoff --- Lib/collections/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 803de0c6792d64..0aeca1ed7e5a74 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