Discuss / Python / 递归方法求解

递归方法求解

Topic source

Lucas_Z_Lee

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

@xiaofeig002的切片应该是最简洁的一种 练习应用递归的方法求解

# -*- coding: utf-8 -*-

def is_palindrome(n):
    n = str(n)
    if len(n) <= 1:
        return True
    elif n[0] != n[-1]:
        return False
    else:
        return is_palindrome(n[1:-1])

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

  • 1

Reply