3 from collections
import defaultdict
6 From python thread http://mail.python.org/pipermail/python-dev/2006-April/063462.html
7 Subject: [Python-Dev] tally (and other accumulators)
9 accumulator = defaultdict(int)
11 accumulator[element] += 1
12 return sorted(accumulator.iteritems())