[Tutor] Nested lists help
Steve Willoughby
steve at alchemy.com
Sat Oct 19 02:53:29 CEST 2013
On 18-Oct-2013, at 17:13, Corinne Landers <corinne.landers at live.com> wrote:
> self.grid_x = x
> self.grid_y = y
> self.grid_z = z
>
> self.grid = []
> self.grid2D = []
>
So here you create a list, self.grid2D.
> for i in range(self.grid_y):
> row = [0]*x
> self.grid2D.append(row)
>
Here you are adding more elements to that list.
> for k in range(z):
> self.grid.append(self.grid2D) #Creates list of x by y grids
>
But here you keep appending self.grid2D multiple times to self.grid. Not z different copies, but they're all the exact name list object, referenced multiple times.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131018/59bfbd3c/attachment.html>
More information about the Tutor
mailing list