def is_palindrome(num): s = int(math.log10(num)+1) # 正数数字长度 if s == 1: return False def get_v(i): return int((num % (10 ** i)) / 10 ** (i-1)) x, y = s, 1 while True: if get_v(num, x) == get_v(num, y): x -= 1 y += 1 else: return False if x <= y: return True output = filter(is_palindrome, range(1, 1000)) print(list(output))
Sign in to make a reply
zzzmode