First post from a Python newbiw

Steve Turner ilkeston at ntlworld.com
Sun Mar 2 09:15:09 EST 2008


I finally decided to have a go with Python and am working through the 
tutorial.

On my old BBC Computer I could do something like this:

DIM A(2,2)

to create a 3 by 3 array of data. Then I could set any point:

A(0,0) = foo
A(0,1) = bar
etc.

In Python I thought I could do this with:

>>> a=[0,0,0]
>>> b=[a,a,a]
>>> b
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
>>> b[1][1]='foo'
>>> b
[[0, 'foo', 0], [0, 'foo', 0], [0, 'foo', 0]]
>>>

I can understand why as b[1][1]='foo' is actually changing a[1]

Apart from doing something like
a=[0,0,0]
b=[0,0,0]
c=[0,0,0]
d=[a,b,c]

is there a better way of creating d??

-- 
Steve
 




More information about the Python-list mailing list