Discuss / Python / 虽然写的得不好,但是终于可以交作业了!

虽然写的得不好,但是终于可以交作业了!

Topic source

JOIEUH

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

-- coding: utf-8 --

def is_palindrome(n):

L = str(n)
x = len(L) // 2
if len(L) % 2 == 1 and L[:x] == L[-1:x:-1]:
    return n
if len(L) % 2 == 0 and L[:x] == L[-1:x-1:-1]:
    return n

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


  • 1

Reply