collections.Counter surprisingly slow

Ian Kelly ian.g.kelly at gmail.com
Mon Jul 29 13:19:22 EDT 2013


On Mon, Jul 29, 2013 at 5:49 AM, Joshua Landau <joshua at landau.ws> wrote:
> Also, couldn't Counter just extend from defaultdict?

It could, but I expect the C helper function in 3.4 will be faster
since it doesn't even need to call __missing__ in the first place.
And the cost (both in terms of maintenance and run-time) of adding
defaultdict to the Counter MRO just to reuse one tiny __missing__
method seems questionable, especially after taking into account that
the constructor signature is incompatible.



More information about the Python-list mailing list