Discuss / Python / 杨辉三角

杨辉三角

Topic source

def triangles():

    s = [1]

    while True:

        yield s

        t = [0] + s + [0]

        s = [t[i] + t[i+1] for i in range(len(t)-1)]

NEVEOOH

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

您好,不好意思问您一下 t = [0] + s + [0]这句怎么理解呢,是把每一行当做一个tuple了吗

龙小天

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

      0   1   0

       \ / \ /

        1   1

       / \ / \

      1   2   1

     / \ / \ / \

    1   3   3   1

   / \ / \ / \ / \

  1   4   6   4   1

 / \ / \ / \ / \ / \

1   5   10  10  5   1


  • 1

Reply