Discuss / Python / 作业

作业

Topic source

祥子920

#1 Created at ... [Delete] [Delete and Lock User]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from functools import reduce

def is_palindrome(n):
    flag = 1
    def fn(x, y):
        nonlocal flag 
        for m in range(0, flag):
            y = y * 10
        flag = flag + 1
        return x + y
    L = [int(x) for x in str(n)]
    return reduce(fn, L) == n

看来大家写的a = a[::-1] 这个非常优秀,我也想要的也是这个结果,不过没有想到-1就是从后往前取,举一反三的能力欠缺


  • 1

Reply