Discuss / Python / 感觉用c语言的二维数组也能解决

感觉用c语言的二维数组也能解决

Topic source
def yanghui(n):
    a=[]
    b=0
    while b<n:
        if b==0:
            a.append(1)
            yield a
        l=[1]+[a[x]+a[x+1] for x in range(0,len(a)-1)]+[1]
        a=l
        yield l
        b=b+1
for  x in yanghui(5):
    print(x)
        

PS D:\pydemo> & C:/Users/Administrator/AppData/Local/Programs/Python/Python37/python.exe d:/pydemo/demo.py

[1]

[1, 1]

[1, 2, 1]

[1, 3, 3, 1]

[1, 4, 6, 4, 1]

[1, 5, 10, 10, 5, 1]


  • 1

Reply