My first stumbling block with Python

Fredrik Lundh fredrik at pythonware.com
Thu Aug 22 10:31:33 EDT 2002


"Mr. Neutron" wrote:

> I found the answer by using a list of lists
>
> MyArray = [ [0]*512 ]
>
> I can now do
>
> MyArray [Y][X] = (X,Y,Z)
>
> and it works fine.
>
> Now my question is what exactly is this code doing? I don't understand
> the way the list is being created (how can I multiply a list?).

see

    http://www.python.org/doc/FAQ.html#4.50

    "4.50. My multidimensional list (array) is broken! What gives?"

and

    http://www.python.org/doc/current/lib/typesseq.html

    "s * n , n * s -> n shallow copies of s concatenated [1]"

    "[1] /.../ Note also that the copies are shallow; nested
    structures are not copied. This often haunts new Python
    programmers /.../"

</F>





More information about the Python-list mailing list