def prob4(dig=3):
    """
    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.
    """
    limit = 10 ** dig - 1

    a = []

    for i in range(limit, 0, -1):

        for j in range(limit, i - 1, -1):
            prod = str(i * j)

            #if len(prod) % 2 == 0:
            half = len(prod) // 2
            palin = [0] * half
            for k in range(half):
                if prod[k] == prod[-k - 1]:
                    palin[k] = 1
                    #print range(half), prod, k, k-1
                    #print palin
            if 0 not in palin:
                a.append(int(prod))

    return max(a)