Discuss / Python / test

def triangles(n): L = [1] while len(L) <= n: yield L L = [1] + [L[i-1] + L[i] for i in range(1, len(L))] + [1] return L

for t in triangles(10): print(t)

圣城简爱

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

请问一下 还是没看懂yield的作用 尤其是把那行去掉结果更诡异

圣城简爱

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

打扰了 突然想通了


  • 1

Reply