Discuss / Python / 各位大佬请指正

各位大佬请指正

Topic source

HIT_Owen

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

def is_palindrome(n):

def num2list(n):
    L = []
    while n > 0:
        q = n % 10
        L.append(q)
        n = (n-q)/10
    return L

L = num2list(n)

count = 0
for v in [x-y for (x,y) in zip(L,L[::-1])]:
    if v == 0:
        pass
    else:
        count = count+1
return count == 0

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

========= RESTART: C:/Users/acer/Desktop/MyPython/find_palindrome.py ========= [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, 212, 222, 232, 242, 252, 262, 272, 282, 292, 303, 313, 323, 333, 343, 353, 363, 373, 383, 393, 404, 414, 424, 434, 444, 454, 464, 474, 484, 494, 505, 515, 525, 535, 545, 555, 565, 575, 585, 595, 606, 616, 626, 636, 646, 656, 666, 676, 686, 696, 707, 717, 727, 737, 747, 757, 767, 777, 787, 797, 808, 818, 828, 838, 848, 858, 868, 878, 888, 898, 909, 919, 929, 939, 949, 959, 969, 979, 989, 999]

HIT_Owen

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

大佬们都好屌,感觉自己写的好low。。。

hotel20000

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

起码你能写,我连看都看不明白


  • 1

Reply