Discuss / Python / 作业

作业

Topic source

极大似然

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

def triangles():

    i = 1    

    l = [1]

    while True:

        yield l

        l = l +[0]    #防止下面的索引超出范围报错

        l = [1] + [l[j]+l[j+1] for j in range(i)]

        i = i + 1


  • 1

Reply