Two-dimensional list


Um, everything is fine, but there is a sentence that says we've created two-dimensional list.
Now, I want to ask you something, since I realized that that list is actually not two-dimensional, just printed
to look that way.

Do you really create two-dimensional list just by printing the code below?
Is that even two-dimensional list, or just looks like that?
If not, could you tell me how to create two-dimensional list?

board = []

for x in range(0, 5):
    board.append(["O"] * 5)

def print_board(board):
    for row in board:
        print " ".join(row)


Technically, a list is only one dimension, linear. But in practice, lists may contain lists, which adds a second index. Notice your board has a list with five rows, each another list with length 5.


will be the last grid element on the first row.


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