Discuss / Python / 交作业

交作业

Topic source
在此插入代码

def is_palindrome(n): return str(n) == str(n)[::-1] print(list(filter(is_palindrome, range(0,1001))))

那儿不远

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

返回布尔值

def is_palindrome(n):
    s = str(n)
    for i in range(len(s)):
        if s[i] == s[len(s)-1-i]:
            return True
        else:
            return False

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

  • 1

Reply