work 没有换成str,有点麻烦不过也行
Topic sourcecopy 一个简单的:
def is_palindrome(n): s_n = str(n) return s_n == s_n[::-1] output = filter(is_palindrome, range(1, 10000)) print('1~10000:', list(output))
- 1
copy 一个简单的:
def is_palindrome(n): s_n = str(n) return s_n == s_n[::-1] output = filter(is_palindrome, range(1, 10000)) print('1~10000:', list(output))
程乔静
-- coding: utf-8 --
def is_palindrome(n): j=1 if n>10: while n/10**j>10: j=j+1 j=j+1
#判断整数的位数 i=int(n/(10**(j-1)))
#算出n整数的最高位值 while j!=0: z=n%10 j=j-1
#算出个位的整数用“%” d=j if i==z: m=int((n%(10**d))/10)
#去掉首位的数字 if m<10: return n else: return is_palindrome(m) else: return False