From 9c066894c5cc1249f6d56565bc24cce13c1fbd11 Mon Sep 17 00:00:00 2001 From: Dan Shernicoff Date: Mon, 27 Jul 2026 20:36:28 -0400 Subject: [PATCH 1/2] Update doc string for `collections.Counter` Added a note that initializing a `Counter` from a `Mapping` or `Counter` will have different behaviour than initializing from other `Iterable`s. --- Lib/collections/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 20f1e728733fec6..376c290f36a6707 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. + Note: If a Mapping or Counter is used to initialize a Counter object + the values from that object will be preserved. + >>> c = Counter('abcdeabcdabcaba') # count elements from a string >>> c.most_common(3) # three most common elements From a3dfa0787d694df17da300da22fd76bc4f0e565a Mon Sep 17 00:00:00 2001 From: Dan Shernicoff Date: Mon, 27 Jul 2026 21:07:39 -0400 Subject: [PATCH 2/2] Change wording to be more clear Updated the wording as it had been unclear. --- Lib/collections/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 376c290f36a6707..5dbcac19e7a9272 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -553,8 +553,8 @@ class Counter(dict): or multiset. Elements are stored as dictionary keys and their counts are stored as dictionary values. - Note: If a Mapping or Counter is used to initialize a Counter object - the values from that object will be preserved. + 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