I am trying to identify and print pairs of 4 digit palindromes that sum up to a 5 digit palindrome.
This is what I have so far
def isPalindrome(x):
return str(x)==str(x)[::-1]
palindrome = [x for x in range(1000, 10000) if isPalindrome(x)]
for x in palindrome:
for y in palindrome:
if (9999 < x+y < 100000) and isPalindrome(x+y):
print(x, y, x+y)
I am estimating the time complexity for this to be O(n^2),because I am traversing the list twice. Is it possible to improve on this?
This is what I have so far
it indicates that the code is not complete and therefore off-topic. \$\endgroup\$