optimized "for x in range" to work like xrange, before `x in range(1000000)` took 16 seconds, now after optimization it only takes 0.007 seconds.