First post from a Python newbiw

Arnaud Delobelle arnodel at googlemail.com
Mon Mar 3 05:32:49 EST 2008



Steve Turner wrote:
> I finally decided to have a go with Python and am working through the
> tutorial.

Great!

> On my old BBC Computer [...]

These were nice machines...

> 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??

It's a FAQ:
http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list

--
Arnaud



More information about the Python-list mailing list