Discuss / Python / 看了你们简洁的代码。。

看了你们简洁的代码。。

Topic source

Nicktimebreak

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

感觉自己弱爆了

def triangles():
    L = [1]
    S = [1]
    while True:
        lg = len(L)
        if lg == 1:
            yield S
        n = 0
        while n < lg-1:
            S = S + [ L[n] + L[n+1] ]
            n = n + 1
        S.append(1)
        L = S    
        yield S
        S = [1]


f = triangles()
p = 0
for i in f:
    print (i)
    p = p + 1
    if p == 12:
        break在此插入代码

  • 1

Reply