# Python杨辉三角实现
def yanghuiTriangle():
L = [1]
L2 = []
while True:
yield L
L = [1]+[L[x-1]+L[x] for x in range(1,len(L))]+[1]#这里如果是range(1,1)的情况前面的L[0]和L[1]中不是取不到值吗?
for item in yanghuiTriangle():
print(item)
if len(item)>10:
break
L = [1] [L[x-1] L[x] for x in range(1,len(L))] [1]#If it is range(1,1), the previous L Aren't there values that cannot be obtained from [0] and L[1]?
When
L = [1],range(1,len(L))isrange(1, 1)and returns[], an empty list, so there is no number of iterations throughfor. So Get the second row of Yang Hui's triangleL = [1] + [1] = [1, 1].list(range(1,1)) is equivalent to returning [] yield and ends recursively.