def triangles():
l=[1]
while True:
yield l
l=[1]+[l[i]+l[i+1] for i in range(len(l)-1)]+[1]
NB你是怎么弄的算法。
使用列表生成式,确实简洁方便。
Sign in to make a reply
一颗美美哒心
l=[1]
while True:
yield l
l=[1]+[l[i]+l[i+1] for i in range(len(l)-1)]+[1]