[Tutor] Minesweeper implementing 20%, weird problem with matrixes

Alberto Troiano albertito_g at hotmail.com
Thu Jul 14 15:36:49 CEST 2005


Hey

I didn't notice that :P
Thanks to Alan, I learn something new with the use of List Comprehension and 
thanks to Danny for the docs, they really helped a lot to understand the 
figure here
I think I can say that Minesweeper implementing 23% with this problem solved

Thanks a lot

Alberto

>From: "Alan G" <alan.gauld at freenet.co.uk>
>To: "Alberto Troiano" <albertito_g at hotmail.com>, <tutor at python.org>
>Subject: Re: [Tutor] Minesweeper implementing 20%,weird problem with 
>matrixes
>Date: Thu, 14 Jul 2005 01:12:18 +0100
>
> > I initialize them by putting None along all the fields
>
>Actually you don't.
>
>     def initialize(self):
>         self.buttonmatrix=[]
>         self.statematrix=[]
>         self.bombmatrix=[]
>
>3 empty lists, so far so good.
>
>         for i in range(self.fil):
>             aux=[]
>             for j in range(self.col):
>                 aux.append(None)
>
>a new list filled with None
>
>             self.buttonmatrix.append(aux)
>             self.bombmatrix.append(aux)
>             self.statematrix.append(aux)
>
>THat same list inserted into all three lists, so they all point
>at the same internal list of Nones. So when you change one,
>you change all.
>
>Try using aux[:] instead to take a copy of aux...
>You could also use list comprehension instead of the loop/append:
>
>aux = [None for i in range(self.col)]
>
>
>HTH,
>
>Alan G.
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list