""" Find the largest palindrome made from the product of two 3-digit numbers. """ def is_palindrome(n): """ Return true if n is a palindrome >>> is_palindrome(23) False >>> is_palindrome(101) True """ list1 = list(str(n)) list2 = list(list1) # make sure this a copy list2.reverse() #print "list1 = ", list1 #print "list2 = ", list2 return list1 == list2 biggest = 0 (ibig, jbig) = (0, 0) for i in range(100, 1000): for j in range(100, 1000): product = i*j if is_palindrome(product): if product > biggest: biggest = product (ibig, jbig) = (i,j) print "biggest is %i * %i = %i" % (ibig, jbig, biggest) if __name__ == "__main__": import doctest doctest.testmod()