Discuss / Python / 不能更短了

不能更短了

Topic source

def y_tri(): L=[1] while True: yield L L=[x+y for x,y in zip(L+[0],[0]+L)]

请问你怎么获得的杨辉三角啊。我用next()始终只跳出来[1],

你是直接写的next(y_tri())吧,应该写g=y_tri(),先生成一个生成器,再调用next(g)。


  • 1

Reply