Newbie confused by 2 dimensional list

haaserd haaserd at yahoo.com
Fri Aug 4 00:53:13 EDT 2000


Hi,
I am trying to create a two dimensional list which will
contain single characters:

>>> L = [["*"] * 2] * 2  # initialize a 2x2 list???
>>> L
[['*', '*'], ['*', '*']]
>>> L[0][1] = 'z'
>>> L
[['*', 'z'], ['*', 'z']]
>>> L[0][1]
'z'
>>>

When I try to set the element L[0][1] to "z", it also sets
L[1][1] to "z".  But I seem to be able to access L[0][1] by
itself.  What am I doing wrong?

TIA




More information about the Python-list mailing list