Discuss / Python / 作业

作业

Topic source

_潴潴俠_

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

def is_palindrome(n):
    s = str(n)
    if len(s)%2>0:
        l = int(len(s)/2+1)
        return s[l-1:] == s[:l][::-1]
    else:
        l = int(len(s)/2)
        return s[l:] == s[:l][::-1]


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

_潴潴俠_

#2 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))

  • 1

Reply