杨辉三角定义如下:
1
/ \
1 1
/ \ / \
1 2 1
/ \ / \ / \
1 3 3 1
/ \ / \ / \ / \
1 4 6 4 1
/ \ / \ / \ / \ / \
1 5 10 10 5 1
def triangles():
… L = [1]
… while True:
… yield L
… L = L + [0] #L.append(0)
… L = [(L[i-1]+L[i]) for i in range(len(L))]
n = 0
results = []
for t in triangles():
print(t)
results.append(t)
n = n + 1
if n == 10:
break