Discuss / Python / 我觉得这个应该很简洁

我觉得这个应该很简洁

Topic source

战鹰二段

#1 Created at ... [Delete] [Delete and Lock User]
#定义函数
def triangles():
    L = [1]
    yield L
    while True:
        L = [v+w for v,w in zip([0]+L,L+[0])]
        yield L
#打印三角
for i,row in enumerate(triangles()):
    print(row)
    if i>=10:
        break

Geek_韧

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

牛啊

逐。

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

而且我刚刚测了下性能,你这个方法也比给数组两侧延长的算法快10%到20%。牛的


  • 1

Reply