回数是指从左向右读和从右向左读都是一样的数,例如12321,909。请利用filter()筛选出回数:
12321
909
filter()
def huishu(n): s1=str(n) s2=str(n)[::-1] return s1==s2 def nature(): n=-1 while True: n=n+1 yield n it=nature() r=filter(huishu,it) for n in r: if n<1000: print(n) else: break