[Tutor] Problem with assigning list elements
Eric Brunson
brunson at brunson.com
Fri Sep 14 21:08:13 CEST 2007
That is not the expected behavior and not the behavior I see:
Python 2.5.1 (r251:54863, May 1 2007, 13:27:01) [C] on sunos5
>>> z = [[1,2],[3,4]]
>>> z[0][0]=100
>>> print z
[[100, 2], [3, 4]]
rgh2 at duke.edu wrote:
> I'm having a problem assigning numbers to a 2-D list.
>
> for the 2d list z for example, when I type in
>
> z[0][0]=67
>
> every zeroth element of every sublist will be set to 67, instead of just element
> [0,0] being set to 67.
>
> If z = [[1,2],[3,4]]
>
> then z[0][0]=100 results in
>
> z= [[100,2],[100,4]]
>
> Is this normal for python? And is there a way to assign to a specific element of
> a 2-dimensional list?
>
> Thanks
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list