[Tutor] Improving My Simple Game Code for Speed, Memory and Learning
wolfrage8765 at gmail.com
Fri Jan 16 17:58:44 CET 2015
On 01/12/2015 04:47 PM, Mark Lawrence wrote:
> I haven't looked carefully at your code but there's always a smell in
> Python when you see structure[x][y]. Can you change the grid so you
> always write something like:-
> for row in grid:
> for cell in row:
> I say this as I'm all for short term pain, long term gain, especially
> when it's guaranteed to eliminate "list index out of range" errors.
Revisiting this, I think I will write a function specifically to perform
look-ups, kind of like your process() function. My purpose is going to
be to prevent out of bounds look-ups. Although none of my posted code
has had potential for this so far, I am writing more code to help play
the game and one of the things I am needing now is to look at the
neighbours of a selected node. This look-up can provide me two errors,
one is the index out of range the and the more subtle error is going
backwards in the list and giving me the end of the list which is not a
I will also use this look-up throughout the rest of my code where possible.
Thank you Mark.
More information about the Tutor