Wow, comments on comments. A comment party.

I like the idea of collections.Counter if it doesn't make things too complicated. I wish I'd thought of it; all my first thoughts involved manual histogramming with defaultdict. No reason to histogram manually if Ray Hettinger has done it for you.