deftriangles():ret=whileTrue:yieldretforiinrange(1,len(ret)):ret[i]=pre[i]+pre[i-1]ret.append(1)pre=ret[:]另一个不用生成器的版本:12345defYangHui(num=10):LL=[]foriinrange(1,num):LL.append([(0ifj==0elseLL[i-1][j-1])+(0ifj==len(LL[i-1])elseLL[i-1][j])forjinrange(i+1)])returnLL