Discuss / Python / 没有别人的 str[::-1]厉害

没有别人的 str[::-1]厉害

Topic source
# -*- coding: utf-8 -*-

def is_palindrome(n):
    x=str(n)
    le=len(x)
    if le==2 and x[0]==x[-1]:
        return n
    elif le==3 and x[0]==x[-1]:
        return n
    elif le==4 and x[0]==x[-1] and x[1]==x[2]:
        return n













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

  • 1

Reply