Battleships Python 2


Hey Guys!

While I’m not stuck, I’m curious to know when our board array became a 2 dimensional array?
Suddenly, I’m told to use syntax like board[i][j] (which is similar to java), but I checked the initial declaration and it’s like this: board = [ ]. When did we change it to become a 2D array?


Wouldn’t need to change. That’s what an empty 2d list looks like.

1 Like

You changed it in step 3:

  • Use range() to loop 5 times.
  • Inside the loop, .append() a list containing 5 "O" s to board , just like in the example above.

So, to that empty list, board, you appended a “list containing 5 “O”'s”, five times. That gives a list of five lists.

1 Like


So if a store 2 or more lists within a list, that makes it a 2d list?

Exactly. That is the meaning of the lst[I][j] notation you mentioned earlier: the element found at index j of that inner list which is at index i of the outer list.