I'm getting an error list index out of range
<p>I'm reading 'Invent Your own Games with Python' and I'm trying to create a game that's in the book. Even though my code matches the code in the book I'm still getting an error:</p>

<pre><code>File "/Users/Rocky/reverso.py", line 251, in &lt;module&gt;
    resetBoard(mainBoard)
  File "/Users/Rocky/reverso.py", line 27, in resetBoard
    board[x][y] = ' '
IndexError: list index out of range
</code></pre>

<p>Code:</p>

<pre><code>def resetBoard(board):
    for x in range(8):
        for y in range(8):
            board[x][y] = ' ' #This is line 27


    board[3][3] = 'X'
    board[3][4] = 'O'
    board[4][3] = 'O'
    board[4][4] = 'X'

def getNewBoard():

    board = []
    for i in range(8):
        board.append([' '] * 8)

        return board



    while True: # line 248
            mainBoard = getNewBoard()
            resetBoard(mainBoard) # This is line 251
            playerTile, computerTile = enterPlayerTile()
            showHints = False
            turn = whoGoesFirst()
            print('The ' + turn + ' will go first.')
</code></pre>

<p>You can initialize your list using this instead:</p>

<pre><code>board = [[' ' for _ in range(8)] for _ in range(8)]
</code></pre>

<p>It should initialize an 8x8 2d list (which will work without errors).</p>

<p>This code works:</p>

<pre><code>def resetBoard(board):
    for x in range(8):
        for y in range(8):
            board[y][x] = ' '


    board[3][3] = 'X'
    board[3][4] = 'O'
    board[4][3] = 'O'
    board[4][4] = 'X'

def getNewBoard():
    return [[' ' for _ in range(8)] for _ in range(8)]

while True: # line 248
        mainBoard = getNewBoard()
        resetBoard(mainBoard) # This is line 251
        playerTile, computerTile = enterPlayerTile()
        showHints = False
        turn = whoGoesFirst()
        print('The ' + turn + ' will go first.')
</code></pre>

python