Both codes by Dennis Lee Bieber are Ok. The 2nd one ("slurper") , seems , a bit faster. I only corrected the author's typo: should be "% div" instead of "/ div". And added this (don't know helped it or not): if div == 1: print lim return And of course: import psyco psyco.full()