def is_palindrome(n): n = str(n) y = "" if len(n) == 1: #排除个位数 return 0 a = len(n) -1 #获取n的最后一个下标 while a >= 0: #通过下标反向读取 x = n[a] y = y+x a = a-1 return y == n output = filter(is_palindrome, range(1, 10000)) print(list(output))
Sign in to make a reply
与非----