Discuss / Python / 作业_生成式

作业_生成式

Topic source

落之萧萧

#1 Created at ... [Delete] [Delete and Lock User]

def triangles(): L = [1] #初始化 yield L #输出第一行 while True: L = [1] + [L[i] + L[i+1] for i in range(len(L)-1)] + [1] #第二行开始:首尾都是1,中间的第i个数是上一行第[i-1]+[i]的和 yield L #输出第i行 pass


  • 1

Reply