膜拜大神的一行代码
Topic source你这个最简洁,比我的强.
在此插入代码
def str_sym(s): #字符串是否对称 n = len(s) b = True i = 0 while i < n: b = b*(s[i]==s[-(i+1)]) i = i +1 return b
def ispalindrome(n): str_n = str(n) # int转换成字符串 return str_sym(str_n)
output = filter(ispalindrome, range(1,1000)) print(list(output))
- 1
九_努力成为BetterMe
直接用str可以将整数转化为字符串,然后切片比较。