L = []
def palindrome(n): L = str(n) s = 0 tag = True while s < (len(L)/2): if L[s] == L[-s-1]: tag = True and tag else: tag = False and tag s = s + 1 return tag
output = filter(palindrome, range(1,1000)) print (list(output))
结果不对,含有100, 101, 102, 103, 104...
抱歉看错代码了
Sign in to make a reply
上辈子是hr
L = []
def palindrome(n): L = str(n) s = 0 tag = True while s < (len(L)/2): if L[s] == L[-s-1]: tag = True and tag else: tag = False and tag s = s + 1 return tag
output = filter(palindrome, range(1,1000)) print (list(output))