I have a nested list of different values (list x in the below code snippet). I also have a for loop that iterates over every index in the list, printing the indices between 0 and 2.
When I have a nested list of the same values (lists y and z in the below code snippet) the loop prints 0 three times.
x = [[1,2,3],[4,5,6],[7,8,9]]
y = [['X' for x in range(3)] for x in range(3)]
z = [['X', 'X' 'X'], ['X', 'X' 'X'], ['X', 'X' 'X']]
for i in x:
print(x.index(i))
for i in y:
print(y.index(i))
for i in z:
print(z.index(i))
Why does the first loop produce 0, 1, and 2 and the second/third loop produce only zeroes? Thanks for your help.
enumerate, notindex.indexis almost never the right tool for any job it's applied to.