3/19


#1

can you please explain why this code creates a grid instead of a siple list with 25
"O"s.???

‘’‘
board = []
for i in range(5):
board.append([‘O’] * 5)
’’’


#2

Because you are appending a list to a list so a 2D list is created.

[“0”] * 5 = [“0”,“0”,“0”,“0”,“0”]

Then that is appended to board:
board = [ [“0”,“0”,“0”,“0”,“0”] ]

If you just wanted 25 elements you should just append elements to the list, not append a list to a list:
board.append(“0” * 5)


#3

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