Discuss / Python / 生成器(copy但看懂大佬代码版)

生成器(copy但看懂大佬代码版)

Topic source

#1 Created at ... [Delete] [Delete and Lock User]

def triangles():

    ls1=[1]

    ls2=[1,1]

    yield ls1

    yield ls2

    lsc=ls2

    while True:

        lsn=[]

        lsn.append(lsc[0])

        n=len(lsc)+1

        for i in range(1,n-1):

            lsn.append(lsc[i-1]+lsc[i])

        lsn.append(lsc[-1])

        yield lsn

        lsc=lsn


  • 1

Reply