def triangles(n): L=[1] while n>0: n=n-1 yield L L.append(0) L=[L[i-1]+L[i] for i in range(len(L))] for n in triangles(6): print(n)