from functools import reduce def is_palindrome(n): if n < 10: return True L = list(str(n)) L.reverse() return reduce(lambda x,y:x*10+y,map(int,L)) == n
#改进一下 def is_palindrome(n): L = list(str(n)) L.reverse() return L == list(str(n))
Sign in to make a reply
蓝色枫叶Babyhong
from functools import reduce def is_palindrome(n): if n < 10: return True L = list(str(n)) L.reverse() return reduce(lambda x,y:x*10+y,map(int,L)) == n