itertools.groupby is a great tool for counting the numbers of occurrences in a sequence. Here are some examples from the interactive interpreter. A list of numbers >>> # Create a random list of numbers >>> from random import random >>> numbers = [int(random() * 10) for x in range(20)] >>> numbers [8, 0, 3, 2, [...]
