Make a list


Oops, try again. It looks like you do not have 5 rows in your list.

not sure why I keep on getting this error. I suppose I can use append to make the code work but in my logic it also should work this way. I use range to have the 5 rows created and then I am using the
board += ["O"]*5 to fill each of the rows with 5 O's, at least that's how I am thinking about it

board = [""]
for i in range(5):
    board += ["O"]*5



You should initalize board to an empty list, not a list with an empty string in it.

Also use board.append() instead of +=, there is a difference between the two:

one_list = [1, 2]
another_list = [1, 2]

one_list.append([1, 2])
another_list += [1, 2]

print one_list        # prints [1, 2, [1, 2]]
print another_list    # prints [1, 2, 1, 2]

See the difference? I added the list [1,2] as an item to one_list, but added the integers 1 and 2 as items to another_list.


thank you, that was really helpful to explain the difference that way!


board = []

for i in range(board_size):

board.append(["O"] *5)


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