#!/usr/bin/env python "Example how to program in Python the Python way" def Look_and_Say(n): "Produce next element of John Horton Conway's Look-and-say sequence" result=[] # return list accumulator for c in str(n): # all the rest digits if result and int(c) == result[-1]: # digit was seen before result[-2]+=1 # increase digit counter else: # new digit result+=[1,int(c)] # add new counter return int("".join(["%d"%c for c in result])) k=1 print 1,k for i in range(2,11): k=Look_and_Say(k) print i,k