[Tutor] Problem with assigning list elements

bob gailer bgailer at alum.rpi.edu
Fri Sep 14 20:29:51 CEST 2007


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]]
>   
When I run that I see:

 >>> z = [[1,2],[3,4]]
 >>> z[0][0]=100
 >>> z
[[100, 2], [3, 4]]

Which is what I'd expect.
> 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