Discuss / Python / filter

filter

Topic source

INVINCIBLEwyq

#1 Created at ... [Delete] [Delete and Lock User]
def is_palindrome(n):
    s = str(n)
    pali_flag = True
    for i in range(len(s)//2):
        pali_flag = pali_flag and (s[i]==s[-i-1])
    return pali_flag

INVINCIBLEwyq

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

看完评论区,发现可以对string进行轻松的反转操作,非常简洁

def is_palindrome(n):
    return str(n)==str(n)[::-1]

  • 1

Reply