Python code from Collective Intelligence.