import math def is_palindrome(num): if num < 10 and num > -10: return True numLen = len(str(num)) tmpNum = num tmpDivide = numLen - 1 while tmpDivide > 0: divide = pow(10, tmpDivide) first = int(tmpNum / divide) tmpLen = len(str(tmpNum)) last = int(str(tmpNum)[tmpLen - 1]) if first != last: return False tmpNum = int((tmpNum - first * divide - last) / 10) tmpDivide = tmpDivide - 2 return True output = filter(is_palindrome, range(10000, 20000)) print(list(output))
Sign in to make a reply
hcy12321