Depending on your version of Python, you might look into `collections.Counter`. I think it is only available in Python 2.7 though. I made a little test that i think is similar to what you have here: http://nbviewer.ipython.org/gist/mythmon/10296382