Discuss / Python / 感觉最省事的做法。。

感觉最省事的做法。。

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

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

傲殇文叆

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

真心给跪了。。。

Eliefly

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

和lz一样,主要是百度到,python数字转换为字符串:str(123)

def is_palindrome(n):        #n=123
    n_str = str(n)            #n_str='123'
    n_invert = n_str[::-1]    #n_invert='321'
    return n_str == n_invert

  • 1

Reply