Discuss / Python / 回数

回数

Topic source

默_kk

#1 Created at ... [Delete] [Delete and Lock User]
在此插入代码

def pali(): '''只有奇数位数字才有可能是回数,''' n = 100 while True: n = n +1 if len(str(n)) % 2 == 1: yield n else: n = n * 10 -1

def _is_pali(n): return lambda x: str(x) == str(x)[::-1]

def palindrome(): it = pali() while True: n = next(it) it = filter(_is_pali(n), it) yield n

for x in palindrome(): if x < 100000: print(x, end = ',') else: break


  • 1

Reply