This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jpeel
Recipients asvetlov, daniel.urban, jpeel, pitrou, rhettinger
Date 2010-12-11.00:26:42
SpamBayes Score 1.8162616e-10
Marked as misclassified No
Message-id <1292027205.69.0.484206035124.issue10667@psf.upfronthosting.co.za>
In-reply-to
Content
I've done as Antoine asked and made a pure Python PyCounter class and a C-enhanced Counter class that both use the mixin CounterBase class. I also added to the tests so that both PyCounter and Counter are tested. I left the update_fromsubs() method in Counter for now, but haven't made a Python equivalent function for PyCounter in case the method is rejected.

Also, I realized that my build was still in debug mode so those benchmark weren't quite accurate (Oops). The Counter class is only 4-6x faster for most cases. That's still good, but not quite as good as I'd previously reported.

Lastly, I thought of one more method that could be quite useful. Say that you have a list like [('apples',4),('oranges',5),('apples',8)] where the second element in each tuple indicates how many of them there are. The resultant Counter should have {'apples': 12, 'oranges':5}. We don't really have a good way to count this, but we could add a small method like the following:

    def fromitems(self, items):
        for key, value in items:
            self[key] += value

and I could easily make a C function for it. I think that this simple method could be very useful to some people. What do you all think of this addition?
History
Date User Action Args
2010-12-11 00:26:47jpeelsetrecipients: + jpeel, rhettinger, pitrou, asvetlov, daniel.urban
2010-12-11 00:26:45jpeelsetmessageid: <1292027205.69.0.484206035124.issue10667@psf.upfronthosting.co.za>
2010-12-11 00:26:43jpeellinkissue10667 messages
2010-12-11 00:26:43jpeelcreate