[Tutor] Making Doubly Linked List with Less Lines of Code.

WolfRage wolfrage8765 at gmail.com
Fri Jan 2 16:53:35 CET 2015

On 01/02/2015 10:37 AM, Alan Gauld wrote:

> I use Thunderbird for posting too, and nobody has complained yet about
> my code layout.
> My account settings are:
> Composition&Addressing
> Compose in HTML - OFF
> Auto quote original then "START REPLY BELOW QUOTE"
> My Tbird prefs are:
> Composition->General tab-> Send Options button
> Text Format set to "Convert to plain text"
> Plain Text domains tab -> includes python.org and gmane.org
> And in my Address book I have the python tutor list entry set to
> Prefers messages formatted as PLAIN TEXT
Using Alan's settings above I can already see the difference in the 
composition window.

Reposting my code to see if it comes out correctly now. I am still 
applying Steve's suggestions.

import sys

class GameTile():
     def __init__(self, col, row, **kwargs):
         # id is (X,Y)
         self.id = str(row) + ',' + str(col)
         self.col = col
         self.row = row

     def __str__(self):
         return '%d, %d' % (self.col, self.row)

class GameGrid():
     def __init__(self, **kwargs):
         self.cols = 8
         self.rows = 8

     def make_grid(self):
         # grid is 2d array as x, y ie [x][y].
         self.grid = [[None] * self.cols for i in range(self.rows)]
         for row in range(self.rows):
             for col in range(self.cols):
                 self.grid[row][col] = GameTile(row=row, col=col)

     def print_by_row(self):
         for col in range(self.cols):
             for row in range(self.rows):

     def print_by_col(self):
         for row in range(self.rows):
             for col in range(self.cols):

     def check_bounds(self, x, y):
         if (0 <= x < self.rows) and (0 <= y < self.cols):
             return True
         return False

     def lookup_node(self, x, y):
         if not self.check_bounds(x, y):
             return False
         return self.grid[x][y]

     def draw_grid(self):
         for col in range(self.cols):
             print(end='| ')
             for row in range(self.rows):
                 print(self.grid[row][col], end=' | ')

grid = GameGrid()

More information about the Tutor mailing list