title: How can I optimize python code: Euler projec prob 4
body: <p>I've been working on  <a href="http://projecteuler.net/problem=4" rel="nofollow">Euler project problem 4</a>, my code works fine but it takes too much time (0.41 seconds).How can I optimize it so that it would take less time.Is there a trick I'm missing, or special functions that I'm not aware of?<br>
  This is the code:</p>
  
  <pre><code>#Note: tpal is a function to test if number is palindrome
  
  pal =0
  
  for i in range(999,100,-1):
      if pal &gt;= i*999:    #A way to get out of loop and to not test on all numbers
          break 
      for j in range(999,100,-1):
          if pal &gt;= i*999:
              break 
          if j &gt; i:                         #numbers would already have been tested so I skip them 
              continue
          pot=i*j
          if ((tpal(pot)==1)and(pot&gt; pal)):
              pal=pot
              i1=i
              j1=j
  
  print(i1,j1,pal)
  
  def tpal(num):
      num=list(str(num))
      Le=len(num)
      if Le == 1: # if number is of one digit than palindrome
          return 1
  
      le=len(num)
  
      if le%2 !=0: #4 example 10101even nbr
          le-=1
      le/2    
  
      for i in range(0,le):
         if num[i]!=num[Le-i-1]:
             return 0
  
      return 1                  
  </code></pre>