Discuss / Python / 中规中矩的解法

中规中矩的解法

Topic source

弦小零

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

可读性差了点儿

def triangles():
    n,tmp = 0,[1]
    while True:
        tmp.append(0)
        res,n = [],n+1
        for i in range(n):
            res.append(tmp[i-1]+tmp[i])
        tmp = res[:]
        yield res

还是这个写的好,py的简洁总是能让人大吃一惊:

a=[1];
while True:
    yield a
    a=[([0]+a)[i]+(a+[0])[i] for i in range(len(a)+1)]

  • 1

Reply