Discuss / Python / 再简单的代码也要亲自敲一遍

再简单的代码也要亲自敲一遍

Topic source

翁岚敏

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

杨辉三角第一次

-- coding:utf-8 --

def triangles():

b=[1,]
while(True):
    yield b
    i=len(b)-1
    while(i):
        b[i]=b[i]+b[i-1]
        i-=1
    b.append(1)

n=0 for t in triangles(): print(t) n = n +1 if n ==10: break

了此本心

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

这个赞。从后往前,就不用考虑先前的赋值改变了后面的结果。 我的代码再优化也是这个思路。


  • 1

Reply