Multidimensional arrays/lists

Gary Herron gherron at
Sun Sep 27 21:43:08 CEST 2009

Someone Something wrote:
> I'm trying to write a little tic-tac-toe program I need a array/list 
> such that I can represent the tic tac toe board with an x axis and y 
> axis and i can access each square to find out whether there is an X or 
> an O. I have absolutely no idea how to do this in python and I really, 
> really, don't want to do this is C.

Here's a 3x3 array (actually a list of lists) filled with space to 
represent the empty board
board = [  [' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' '] ]

And here's two moves, X grabs the center, and O grabs the upper right
board[1][1] = 'X'
board[0][2] = 'O'

And so on.

Gary Herron

More information about the Python-list mailing list