Discuss / Python / 参考别人写的

参考别人写的

Topic source

def triangles(maxt):
    b=[1]
    while len(b)<maxt:
      yield(b)
      b=[1]+[ b[i]+b[i+1] for i in range(len(b)-1) ]+[1]

for t in triangles(10):print t

deaddeaddead2

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

有一个小问题,第三行应该是小于等于才行

def triangles(maxt): b=[1] while len(b)<=maxt: yield(b) b=[1]+[ b[i]+b[i+1] for i in range(len(b)-1) ]+[1]

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

老阿_

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

能解释下代码吗?很精简,运行也正确,但是看不懂。


  • 1

Reply