may be a dumb question,but I can't understand why?

Aaron Sterling dhaaron at hotpop.com
Wed Nov 14 01:32:51 EST 2001


> the following function is in bpnn.py
> def makeMatrix(I, J, fill=0.0):
>     m = []
>     for i in xrange(I):
>         m.append([fill]*J)
>     return m
> 
> I rewrite it to :
> def makeMatrix(I, J, fill=0.0):
>     m=[[fill]*J]*I
>     return m
> the result is defference
> Can someone tell me the defference between the two function?

it seems to work alright on my machine. I defined a function to test it to arbitrary parameters without a proplem.

def test(max):
    i = j = 0
    for i in xrange(max):
        for j in xrange(max):
            if makeMatrix(i, j) != makeMatrix2(i, j):
                print i, j


Aaron,  dhaaron at hotpop.com





More information about the Python-list mailing list