Discuss / Python / Palindrome 练习

Palindrome 练习

Topic source
# To divide a num to list
def num2list(n):
    L = []
    while n > 0:
        L.append(n % 10)
        n = int(n / 10)
    return L

# To decide whether the number is palindrome
def is_palindrome(n):
    num_list = num2list(n)
    # cmp_list = num2list(n)[::-1]
    cmp_list = num_list[::-1]
    if num_list == cmp_list:
        return n

  • 1

Reply