def revnum(x): out = 0 while x != 0: out *= 10 out += x % 10 x /= 10 return out def isL(x_ori): x = x_ori x += revnum(x) n = 0 while n < 50: x_ = revnum(x) if x_ == x: return False x += x_ n += 1 return True def test(x): n = 0 while n < 50: print x x_ = revnum(x) if x == x_: break x += x_ n += 1 import time a0 = time.clock() be = [] for i in xrange(1, 10001): if isL(i): be.append(i) a1 = time.clock() print be print a1 - a0