[Tutor] Nested lists help

Corinne Landers corinne.landers at live.com
Sat Oct 19 02:13:27 CEST 2013


Hi, 
I'm trying to create a 3D grid, so I'm using a list of list of lists. However, if I try to make a change to one value, eggrid[0][1][2] = 3, It doesn't just change list[0], it change the 2nd element in the 1st list of every list? I think it's because I've copied lists to get the grid, but could you help me fix this? 
This is my code, that takes an x,y,z value from user. 
self.grid_x = xself.grid_y = yself.grid_z = z
self.grid = []self.grid2D = []
for i in range(self.grid_y):            row = [0]*x            self.grid2D.append(row)
for k in range(z):            self.grid.append(self.grid2D) #Creates list of x by y grids
Thank you so muchCorrine 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131019/82cf8a11/attachment.html>


More information about the Tutor mailing list