Discuss / Python / tmp=L[:]

tmp=L[:]

Topic source

Dokuroo

#1 Created at ... [Delete] [Delete and Lock User]
def triangles():
L=[1]
yield L
while True:
    i=1
    tmp=L[:] #如果直接让tmp=L,改变tmp就会改变L
    tmp.append(1)      
    while i <len(L):
        tmp[i]=L[i-1]+L[i]
        i+=1
    L=tmp
    yield L

  • 1

Reply