Problem with nested lists as arrays
Terry Reedy
tjreedy at udel.edu
Mon Feb 14 12:31:42 EST 2005
More information about the Python-list mailing list
Mon Feb 14 12:31:42 EST 2005
- Previous message (by thread): Problem with nested lists as arrays
- Next message (by thread): safest way to open files on all platforms
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
<benjamin.cordes at blawrc.de> wrote in message news:1108382521.266024.281620 at g14g2000cwa.googlegroups.com... 'Having trouble' is too vague to figure out. However, I would delete this: > def getEmptySlot(self): > i = 0 > j = 0 > while i <= self.dim-1: > while j <= self.dim-1: > if self.elements[j][i] == -1: > return [j, i] > j = j+1 > j = 0 > i = i + 1 and maintain an .empty attribute, which is trivially updated in > def swapElements(self, fromx, fromy, tox, toy): > dummy = self.elements[toy][tox] > > self.elements[toy][tox] = self.elements[fromy][fromx] > self.elements[fromy][fromx] = dummy as (fromy,fromx). Note that there is no need to pass tox, toy to this routine. Indeed, I would include the last two lines in your move routine. Since dummy is always the same object, I would also just keep it as self._dummy instead of looking it up each time. Terry J. Reedy
- Previous message (by thread): Problem with nested lists as arrays
- Next message (by thread): safest way to open files on all platforms
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list