[issue35892] Fix awkwardness of statistics.mode() for multimodal datasets

Raymond Hettinger report at bugs.python.org
Sat Feb 16 12:44:35 EST 2019


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

> We can return the smallest value from the **table** instead
> of the code below.

Internally, that does too much work and then throws most of it away.

The difference between Counter(data).most_common()[1] and Counter(data).most_common(1) is that the former materializes the entire items iterator into a list and does a full sort, while the latter is memory friendly and makes a single pass with min().

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35892>
_______________________________________


More information about the Python-bugs-list mailing list