I got a 2 dimensional list:
[[5, 80, 2, 57, 5, 97], [2, 78, 2, 56, 6, 62], [5, 34, 3, 54, 6, 5, 2, 58, 5, 61, 5, 16]]
In which I need to change every second element to 0, starting from first one. So it should look like this:
[[0, 80, 0, 57, 0, 97], [0, 78, 0, 56, 0, 62], [0, 34, 0, 54, 0, 5, 0, 58, 0, 61, 0, 16]]
Algorithm I use:
for i in tempL: for j, item in enumerate(i):if i.index(item) % 2 == 0:print('change, index:'),print(i.index(item))i[j] = 0else:print('not change, index:'),print(i.index(item))
But what I get is this:
change, index: 0
not change, index: 1
change, index: 2
not change, index: 3
change, index: 4
not change, index: 5
change, index: 0
not change, index: 1
change, index: 2
not change, index: 3
change, index: 4
not change, index: 5
change, index: 0
not change, index: 1
change, index: 2
not change, index: 3
change, index: 4
not change, index: 5
change, index: 6
not change, index: 7
not change, index: 5
not change, index: 9
not change, index: 5
not change, index: 11
[[0, 80, 0, 57, 0, 97], [0, 78, 0, 56, 0, 62], [0, 34, 0, 54, 0, 5, 0, 58, 5, 61, 5, 16]]
Some elements are not changed, and it's because (I added index print to see that) it thinks that index of those elements are 7 and 9 for some reason. What can it be, because I am looking for a bug for so long still cannot find..
I double checked, there are not extra spaces or anything in the list.