proposition for syntax for initialisation of multidimensionallists

Russell Blau russblau at hotmail.com
Tue Oct 12 23:16:45 CEST 2004


"Batista, Facundo" <FBatista at uniFON.com.ar> wrote in message
news:mailman.4775.1097615531.5135.python-list at python.org...
>
> You don't need list comprehensions::
>
> >>> [[[0] * 4] * 3] * 2
> [[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 0, 0], [0, 0, 0, 0],
> [0, 0, 0, 0]]]
>

Lists are mutable...  ;-)

>>> x = [[[0] * 4] * 3] * 2
>>> x[0][1][2] = "foo!"
>>> x
[[[0, 0, 'foo!', 0], [0, 0, 'foo!', 0], [0, 0, 'foo!', 0]], [[0, 0, 'foo!',
0], [0, 0, 'foo!', 0], [0, 0, 'foo!', 0]]]

-- 
I don't actually read my hotmail account, but you can replace hotmail with
excite if you really want to reach me.





More information about the Python-list mailing list