Python生成器实现杨辉三角打印

1 def triangles():
2     c = [1]
3     while 1:
4         yield c
5         a,b=[0]+c,c+[0]
6         c=[a[i]+b[i] for i in range(len(a))]
1 n = 0
2 for t in triangles():
3     print(t)
4     n = n + 1
5     if n == 10:
6         break
原文地址:https://www.cnblogs.com/paomaliuju/p/5019301.html