A simple question

Tuvas tuvas21 at gmail.com
Sun Mar 5 05:01:34 CET 2006


I know the answer is probably really simple to this, and I feel bad to
even ask, but I can't find the answer anywhere... Let me show what
happened, then ask the question.

>>> x=[[0]*2]*2
>>> x
[[0, 0], [0, 0]]
>>> x[0][1]=1
>>> x
[[0, 1], [0, 1]]
>>>

The question now. Why is the output list [[0, 1], [0, 1]] and not [[0,
1], [0, 0]]? And how can I make it work right? I do know that x[0][1]
will always give the value of that specific coordinate, but never
before have I tried to manipulate rows like this, and I'm finding I
need to. Thanks!




More information about the Python-list mailing list