Simple Counters in Python (with Benchmarks)

It's sometimes necessary to count the number of distinct occurrences in an collection. For example, counting how many times each letter occurs in a block of text. Or sorting a list by its most common member.

If I were to do this sort of counting with SQL, I would generally …