Counter also consider any missing key has the value "0".
With the constructor (accepting any iterable) and the most_common(n), it's just a very set of features if you need to count anything.
Le 13/07/2018 à 19:45, Michael Selik a écrit :
On Mon, Jul 2, 2018 at 8:49 AM Chris Barker <firstname.lastname@example.org mailto:email@example.com> wrote:
On Fri, Jun 29, 2018 at 11:25 PM, Guido van Rossum <firstname.lastname@example.org <mailto:email@example.com>> wrote: Hm, this actually feels heavier to me. But then again I never liked or understood the need for Counter -- actually, me neither -- and partly because it's too lightweight -- that is, it's still a regular dict, and you pretty much have to know that to use it. That it, it provides a nice counting constructor, but after that, it's just a key:integer dict :-)
Counter provides ``most_common`` which is often implemented inefficiently if written from scratch. People mistakenly use ``sorted`` instead of ``heapq.nlargest``.
Python-ideas mailing list Pythonfirstname.lastname@example.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/