Discuss / Python / 杨辉三角

杨辉三角

Topic source

岁益寒

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

# -*- coding: utf-8 -*-

def triangles():

    n , L1 , L2 = 1, [] , [1]

    while True:

        yield L2

        L=L2.copy()

        L.insert(0,0)

        L.append(0)

        L1,L2=L2.copy(),[]

        L2=[L[i]+L[i+1] for i in range(len(L)-1)]


  • 1

Reply