Counting number of each item in a list.

Justin Azoff justin.azoff at gmail.com
Sun Mar 19 14:22:57 EST 2006


Bruno Desthuilliers wrote:
> And of course, I was right. My solution seems to be faster than Paul's
> one (but slower than bearophile's), be it on small, medium or large lists.

Your version is only fast on lists with a very small number of unique
elements.

changing mklist to have
items = range(64) instead of the 9 item list and re-timing you will get
"better" results:

A100 (10000 times): 7.63829684258
B100 (10000 times): 1.34028482437
C100 (10000 times): 0.812223911285

A10000 (100 times): 9.78499102592
B10000 (100 times): 1.26520299911
C10000 (100 times): 0.857560873032

A1000000 (10 times): 87.6713900566
B1000000 (10 times): 12.7302949429
C1000000 (10 times): 8.35931396484



-- 
- Justin




More information about the Python-list mailing list