turns = [4, 6, 2, 8, 1, 9, 5, 5, 3, 7, 6, 8, 2, 4]
turns.append([1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4])
turns.append([4, 6, 2, 8, 1, 9, 6, 5, 3, 7, 6, 8, 2, 4])
turns.append([0, 0, 26, 24, 3, 7, 5, 4, 25, 25, 21, 21, 21, 21])
turns.append([0, 0, 0, 0, 7, 3, 8, 2, 0, 0, 29, 29, 29, 29])
turns.append([0, 0, 0, 0, 26, 24, 0, 0, 0, 0, 0, 0, 0, 0])
arrayValue = turns[j][i]
if arrayValue == turnCurrently:
Error Message:
Traceback (most recent call last):
File "D:/a45d32f947055690c690d94f88/TicTacToe", line 183, in <module>
arrayValue = turns[j][i]
TypeError: 'int' object is not subscriptable
My question is essentially, I want to test if turns[j][i] is equal to turnCurrently but I keep running into this subscriptable problem, I haven’t been able to find this answered anywhere I think that this is a very important question. Thanks in advance,
Richard
It often helps a lot to print out the content of your variables to see what it happening:
As you can see, the first few elements of that list are simple integers, but not a list of ints. So when
jis small, it will select anintand try to apply[i]on it – which fails.The solution in this case is to put the first elements into an extra list:
Another way would be to initialize your list as an empty list, and append the first sub-list as well: