A palindromic number reads the same both ways. The largest palindrome  made from the product of two 2-digit numbers is 9009 = 91  99.Find the largest palindrome made from the product of two 3-digit  numbers.How would you improve the following code?I'm looking specifically for:performance optimizations ways to shorten the code more pythonic ways to write it   def is_palindrome(num):        return str(num) == str(num)[::-1]            def fn(n):        max_palindrome = 1        for x in range(n,1,-1):            if x * n < max_palindrome:                 break            for y in range(n,x-1,-1):                if is_palindrome(x*y) and x*y > max_palindrome:                    max_palindrome = x*y                elif x * y < max_palindrome:                    break        return max_palindrome    print fn(999)
Project Euler #4 - Largest Palindrome Product
python;optimization;project euler
The function is_palindrome converts num to a string twice. You might consider:def is_palindrome(n):   Return True if n is a palindrome; False otherwise.   s = str(n)   return s == s[::-1]And then for the main loop I would write:from itertools import productmax(x * y for x, y in product(range(1000), repeat=2) if is_palindrome(x * y))This runs in less than a second so I think it is not worth putting lots of effort into optimizing it.