Discuss / Python / 作业

作业

Topic source

Gussun

#1 Created at ... [Delete] [Delete and Lock User]
#生成序列
def _odd_():
    n=1
    while True:
        n=n+1
        yield n 

#定义筛选函数
def _shaixuan(n):
    return str(n)==str(n)[::-1]

def _shai():
    yield 1
    it=_odd_()
    while True:
        n=next(it)
        yield n
        it=filter(_shaixuan,it)

for n in _shai():
    if n<1000:
        print(n)
    else:
        break

  • 1

Reply