How do I set the list element


#1

How do I set the list element at guess_row, guess_col to “X” in the Battleship game (step 11)?


FAQ: Learn Python - Battleship - Danger, Will Robinson!
#2

Remember how to call an element from a 1-dimensional list? (i.e. list[2])
So in a 2-dimensional list, you add more info to it --> list[2][3]
To put it in the context, I had board[guess_row][guess_col] and set it equal to string X.


#3

To add to the above, once we declare which index is for the row, and which is for the column, we cannot switch that around.

board[row][col]

The row index is always first, and column index always second.


#4

Thank you so much @cirrus11. I totally get it now!


#5

Thank you for the additional information @mtf! I appreciate it !


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.