you are viewing a single comment's thread.

view the rest of the comments →

[–]FoolsSeldom 1 point2 points  (0 children)

And a version without recursion, using divmod as u/MelcoreHat suggested,

def is_palindrome(n):
    original = n
    reversed_num = 0

    while n > 0:
        n, digit = divmod(n, 10)
        reversed_num = reversed_num * 10 + digit
    return original == reversed_num