def create_board():
b = [[['',''] for i in range(8)] for j in range(8)]
return b
game_board = create_board()
for i in game_board[0]:
for idx, val in enumerate(i[1::2]):
idx[0] = 0
idx[1] = 0
print game_board
I have the this script, in which I need to iterate through the first list that is within the list game_board. Starting at the second element I need to change the values in every other element's list. However when I run this I am greeted with the error
idx[0] = 0
TypeError: 'int' object does not support item assignment
It would be understandable if IDLE was complaining about me assigning a variable to a str, (which would be an issue with iterating over values rather than indices), but i can't see why this problem is happening considering I have no integers.
enumerate()pairs each item in your sequence with its index:(index, item).