mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue #20478: avoid special casing Counter in statistics
Passing Counter objects to the Counter constructor is special cased, going through iter() firsts ensures they are handled the same way as any other iterable. (Committing on Steven's behalf as I don't believe his SSH key is registered yet)
This commit is contained in:
parent
ec1c8097c1
commit
bfd68bf4ac
3 changed files with 12 additions and 3 deletions
|
@ -268,9 +268,7 @@ def _coerce_types(T1, T2):
|
|||
|
||||
def _counts(data):
|
||||
# Generate a table of sorted (value, frequency) pairs.
|
||||
if data is None:
|
||||
raise TypeError('None is not iterable')
|
||||
table = collections.Counter(data).most_common()
|
||||
table = collections.Counter(iter(data)).most_common()
|
||||
if not table:
|
||||
return table
|
||||
# Extract the values with the highest frequency.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue