代码如下:
def is_palindrome(n):
L=str(n)
x=len(L)
T=[]
for i in range(x//2):
t=L[i]==L[-1-i]
T.append(t)
return False not in T
'''测试:
output = filter(is_palindrome, range(1, 1000))
print('1~1000:', list(output))
if list(filter(is_palindrome, range(1, 200))) == [1, 2, 3, 4, 5, 6,7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99,101, 111, 121, 131, 141,151, 161, 171, 181, 191]:
print('测试成功!')
else:
print('测试失败!')
'''
'''测试结果:
>>> output = filter(is_palindrome, range(1, 1000))
>>> print('1~1000:', list(output))
1~1000: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, 212, 222, 232, 242, 252, 262, 272, 282, 292, 303, 313,