Discuss / Python / 哎

Nicktimebreak

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

shit,看见人家一行就解决了

import math
def is_palindrome(n): # n=12321
    nl  = []
    bs = 1
    while n // bs != 0:
        nl.append(n // bs % 10)
        bs = bs * 10
    bit = len(nl)
    i = 0
    while nl[i] == nl[bit - i -1]:
        i += 1
        if i == bit:
            break
    if i == bit:
        return True
    else:
        return False

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

  • 1

Reply