List Count

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Apr 22 12:06:12 EDT 2013


On 22 April 2013 16:50, Blind Anagram <blindanagram at nowhere.org> wrote:
>>
>> It would be very easy to subclass list and add this functionality in
>> cython if you decide that you do need a builtin method.
[snip]
>
> But I was really wondering if there was a simple solution that worked
> without people having to add libraries to their basic Python installations.

There are simple solutions and some have already been listed. You are
attempting to push your program to the limit of your hardware
capabilities and it's natural that in a high-level language you'll
often want special libraries for that.

I don't know what your application is but I would say that my first
port of call here would be to consider a different algorithmic
approach. An obvious question would be about the sparsity of this data
structure. How frequent are the values that you are trying to count?
Would it make more sense to store a list of their indices?

If the problem needs to be solved the way that you are currently doing
it and the available methods are not fast enough then you will need to
consider additional libraries.

>
> As I have never tried building an extension with cython, I am inclined
> to try this as a learning exercise if nothing else.

I definitely recommend this over writing a C extension directly.


Oscar



More information about the Python-list mailing list