-- coding: utf-8 --
def is_palindrome(x):
s=str(x)
i=0
j=len(s)-1
while s[i]==s[j] and j-i>=0 :
i=i+1
j=j-1
if j-i<=0 : return x
测试:
output = filter(is_palindrome, range(1, 100))
print(‘1~100:’, list(output))
if list(filter(is_palindrome, range(1, 100))) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 11,22,33,44,55,66,77,88,99]:
print(‘测试成功!’)
else:
print(‘测试失败!’)
List item