nested lists as arrays

Fredrik Lundh fredrik at pythonware.com
Mon Feb 14 11:54:29 EST 2005


"naturalborncyborg" <benjamin.cordes at blawrc.de> wrote:

> Hi, I'm using nested lists as arrays and having some problems with
> that approach. In my puzzle class there is a swapelement method which
> doesn't work out.

what happens, and what do you expect?

> Any help and comments on the code will be appreciated.

is it elements[y][x] or elements[x][y]?  both variants seem to be used
in your code.

(fwiw, in this case, using a dictionary might be a lot easier.  store cells
as elements[x, y], use elements.get((x, y)) is None to check for empty
cells, use elements[x, y] = None or del elements[x, y] to empty a cell,
use elements = {} to clear all cells, etc).

</F> 






More information about the Python-list mailing list