palindromes of sums less than 30, help to optimize my code
<p>On my way of studying Python i stacked on the problem:<br><br>
I have to count all numbers from <b>0</b> to <b>130000</b> which are palindromes, but they should be palindromes after sum of the number and its reversed version. For example: 
<br> <code>i</code> = 93 
<br>93 + 39 = 132
<br>132 + 231 = 363
<br><code>count_of_palindromes</code> should count all <code>i</code> which are palindromes after <b>1</b> or more iterations of summing, but less than <b>50</b>.
<br>I've already written the code but it's too way difficult to run on my PC, Python stops responding :( 
<br><br>Any advices how to optimize my code?</p>

<pre><code>        count_of_palindromes = 0
        for i in range(0,130000):
            trying = 0
            if (i == int(str(i)[::-1])) != True:
                trying += 1
                sum = i + int(str(i)[::-1])
                while trying &lt;= 50:
                    while (sum == int(str(sum)[::-1])) != True:
                        trying += 1
                        sum += int(str(sum)[::-1])                
                    if trying &gt; 0 and trying &lt;= 50:
                        count_of_palindromes += 1
                        break
        print(count_of_palindromes)
</code></pre>

<p>Thank you very much!</p>

<p>This solution has a lot of conversions so it may not be the best solution but regardless it is a solution. have a look at this post he has a seemingly much better method of reversing integers without conversion
<a href="http://stackoverflow.com/a/3806212/1642546">http://stackoverflow.com/a/3806212/1642546</a> </p>

<p>If you combine my code and that posts code. you probably will have a faster solution, but you must benchmark it to see. </p>

<pre><code>token = 0
for x in range(130000):
   reversed = str(x)[::-1]
   original = str(x)
   sum = int(reversed) + int(original)
   if str(sum) == str(sum)[::-1]:
      token+=1
print(token)
</code></pre>

python optimization