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.
[color=blue][color=green][color=darkred]
>>> x=[[0]*2]*2
>>> x[/color][/color][/color]
[[0, 0], [0, 0]][color=blue][color=green][color=darkred]
>>> x[0][1]=1
>>> x[/color][/color][/color]
[[0, 1], [0, 1]][color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
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!
even ask, but I can't find the answer anywhere... Let me show what
happened, then ask the question.
[color=blue][color=green][color=darkred]
>>> x=[[0]*2]*2
>>> x[/color][/color][/color]
[[0, 0], [0, 0]][color=blue][color=green][color=darkred]
>>> x[0][1]=1
>>> x[/color][/color][/color]
[[0, 1], [0, 1]][color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
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!
Comment