Two-dimensional arrays

Terry Reedy tjreedy at udel.edu
Mon May 26 18:27:53 EDT 2003


"Peter Slizik" <peter.slizik at pobox.sk> wrote in message
news:batgj9$3bfpi$1 at ID-196014.news.dfncis.de...
> I created the 2-dim array using
>
>  >>> dim = 5
>  >>> array = [[0]*dim]*dim
...
> Then I tried to change some elements:
>
>  >>> array[1][2] = 1
>
> The result looks quite strange:

This is a known pitfall for Python beginners.  You are perhaps the
10th person in the last several years to do and ask the same ;-)

Terry J. Reedy







More information about the Python-list mailing list