How did the board get 2D?

#1

Hi there,

I'm not really stuck at any particular exercice per se, but I still got a question on how this all works nonetheless.

In this lesson, we're playing around with a 2 dimensional list. However, I'm not sure I understand how it even got 2 dimensional in the first place.

From my point of view, it looks like we're basically just printing 5 lines of "O"'s one under the other in the console so il looks prettier and 2 dimensional (to the human eye). How the computer got to see it that way too, however, is still a mystery to me. I dont recall telling him that the first item of each list was linked by the "column" concept with the first item in the row under it, etc.

The reason why I'm asking this is that it is clearly possible to make the list behave in a 2D fashion, as made clear by this line in exercice 11. Danger, Will Robinson!, which effectively replaces the right "O" with an "X" in the 2D board.

`` board [guess_row][guess_col] = "X"``

#2

The board is a list of lists. If you look at it,

``````[
['O', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', 'O', 'O'],
]``````
``````board[0]     =>  ['O', 'O', 'O', 'O', 'O'],

board[0][0]  =>  O``````

#3

That makes much sense!

Thank you!!

#5

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