Counting occurrences in a sequence with itertools.groupby

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, […]

Making the robot dance

Some time around 1980, my elementary school classroom got a computer. While most of the other kids fooled around playing Hunt the Wumpus, my friend and I found the BASIC manual that came with the computer. We laboriously copied in the code to make a "robot" appear on the screen. After a lot of typos, […]