On 02/09/2015 08:46 PM, Chris Angelico wrote: > > class Grid: > blah blah > > def __iter__(self): > for row in range(self._rows): > for col in range(self._cols): > if self._grid[row][col]: > yield self._grid[row][col]
I strongly suggest you remove the if self._grid[row][col]: line. Best case scenario: the entire grid is blank, and iterating through it does nothing. Worst case scenario: only some elements evaluate as False, so your loop doesn't execute the full number of times; i.e. with a grid of 4x5 with 7 blank cells you get 13 iterations -- probably not what was expected. -- ~Ethan~
signature.asc
Description: OpenPGP digital signature
-- https://mail.python.org/mailman/listinfo/python-list