Discuss / Python / 迭代

迭代

Topic source

梅泽Maeser

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

两边附加1, 中间用上一行的对应位置相加就行。注意好长度。

def triangles():
    L = [1]
    yield L
    while True:
        L = [1] + [ L[i] + L[i + 1] for i in range(len(L) - 1) ] + [1]
        yield L

  • 1

Reply