I am a beginner learning python. I have a problem with this for loop.
I am trying to a search loop for pc to track the move made by the player (human) and to anticipate the next move in a tic tac toe game.
As a result, I create a for loop to append the moves made by the player(human) but something strange happens
lst = [ [ "X",[], [] ],
[ [], "X", [] ],
[ [], "X", [] ] ]
temp_lst = []
for i in lst:
lst_1 = []
for j in i:
if j == "X":
lst_1.append(lst.index(i))
print(lst.index(i))
lst_1.append(i.index(j))
print(i.index(j))
temp_lst.append(lst_1)
print (temp_lst)
The results on my IDLE is:
0
0
1
1
1
1
[[0, 0], [1, 1], [1, 1]]
Note that the position of the "X" IN THE MIDDLE and the "X" int the last list is the same which would not be. This is my problem. Note that when I change the lst to:
lst = [ [ "X",[], [] ],
[ [], "X", [] ],
[ [], [], "X" ] ]
result: [[0, 0], [1, 1], [2, 2]]
The result from python shows the correct position of the last "X" but in the previous one it gave the strong position for the last "X"
Please help thank you