def select(N): for n in range(11,N): s = str(n) ls = len(s) if ls % 2 ==0: hl = ls//2 tmp = hl else: hl = (ls - 1)//2 tmp = hl + 1 compare = list( (s[i] == s[tmp + i]) for i in range(hl)) if all(compare): print(n)
只需要设置筛选的最大值,然后利用循环一个个排查,筛选出回数
起始也可以把range(11,N)改成range(11,N,10),因为两个回数之间最少也相隔10,例如101,111,121。。
Sign in to make a reply
我就是梦想在望
def select(N):
for n in range(11,N): s = str(n) ls = len(s) if ls % 2 ==0: hl = ls//2 tmp = hl else: hl = (ls - 1)//2 tmp = hl + 1 compare = list( (s[i] == s[tmp + i]) for i in range(hl)) if all(compare): print(n)