nested lists as arrays

Michael Spencer mahs at telcopartners.com
Mon Feb 14 12:13:06 EST 2005


naturalborncyborg 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 "doesn't work out"?  On casual inspection that method seems to "work":

  >>> p = Puzzle(2)
  >>> p.elements[0][0] = 1
  >>> p.elements[1][1] = 2
  >>> p.elements
[[1, 0], [0, 2]]
  >>> p.swapElements(0,0,1,1)
  >>> p.elements
[[2, 0], [0, 1]]
  >>>

What should it do instead?

Michael




More information about the Python-list mailing list