Discuss / Python / less is good

less is good

Topic source

SANTOS_WU

#1 Created at ... [Delete] [Delete and Lock User]
def is_palindrome(n):
    return str(n)==str(n)[::-1]

output = filter(is_palindrome, range(1, 1000))
print(list(output))

这个打印出来好像不对啊。

_Ljj110719

#3 Created at ... [Delete] [Delete and Lock User]

赞!!!

def is_palindrome(n):
    return str(n) == str(n)[::-1] and n / 10 != 0

output = filter(is_palindrome, range(1, 1000))
print(list(output))
应该要去除个位数,个位数并不算回数。

罗修TM

#5 Created at ... [Delete] [Delete and Lock User]

回复楼上,为什么不算?个位数同样满足条件


  • 1

Reply