Use a faster algorithm
Replace range with xrange