Project Euler: #36 Binary and Base 10 Palindromes
Are there any such other optimizations that I have missed that I can use to reduce runtime and in general make my code more useful.


Yes. You're thinking about the problem backwards. As far as I can tell, your solution may be as fast as you can do in Python solving the problem directly. That is, something like:

sum(filter(satisfies_problem, xrange(1, 1000000))


But we can do way better. Palindromes are fairly sparse, so rather than go through a million numbers and checking them to see, we can actually just generate all the palindromes in one base and just check if they're a palindrome in the other base. Basically, for every number from 1 to 1000 we can just add its reverse with or without duplication (e.g. 146 can become the palindromes 14641 and 146641). That is:

def make_palindrome(p, repeat):
    result = p 
    if not repeat: p //= 10
    while p &gt; 0:
        result = result * 10 + p % 10
        p //= 10
    return result


Then we can just generate all the right palindromes, base 10, and check if they match base 2:

total = 0 
cap = upper_limit / 10 ** (math.log10(upper_limit)/2)
for p in xrange(int(cap) + 1): 
    for repeat in (True, False):
        pal = make_palindrome(p, repeat)
        if pal &amp; 1 and lower_limit &lt;= pal &lt;= upper_limit:
            as_bin = bin(pal)[2:]
            if as_bin == as_bin[::-1]:
                total += pal 

return total


Timing comparison, this is 100x faster:

Brute Force Search    0.3477s
Palindrome Generator  0.0030s