You mentioned it a bit, but I want to make it clear that, even if you don't use 2.7, you can still count by doing:<p><pre><code> from collections import defaultdict
counter = defaultdict(int)
</code></pre>
There is a difference though, because you have to count manually, i.e:<p><pre><code> for i in 'supercalifragilisticexpialidocius':
counter[i] += 1
</code></pre>
Also, because defaultdict accepts any callable, you can have a dict of counters by doing:<p><pre><code> counters = defaultdict(lambda: defaultdict(int))
for word in ['apple', 'berry', 'grape']:
for letter in word:
counters[word][letter] += 1
</code></pre>
This is not very obvious, so I don't use it a lot, but sometimes it's the most elegant solution.