I'm trying to do a fairly trivial operation in Python, but am stumped as to why I'm getting the error message in the title on the moment_list.remove(moment_list[i])
line. My code is:
for i in range(0,len(moment_list_sum)):
if moment_list_sum[i]==nMoments:
moment_list.remove(moment_list[i])
LHS.remove(LHS[i])
else:
pass
As you can see I am trying to remove the indices from two lists moment_list
and LHS
that meet the condition in the if loop, of the same indices in the other list being equal to nMoments.
Going into the loop nMoments is an int equal to 3, and the lists are:
LHS [y_0, y_1, yx1, yx2, yx3, yx4, yx5, yx6, yx7]
moment_list [[1, 0], [0, 1], [0, 2], [1, 1], [2, 0], [0, 3], [1, 2], [2, 1], [3, 0]]
moment_list_sum [1, 1, 2, 2, 2, 3, 3, 3, 3]
They are all the same length so I've no idea why I'm getting a list index error, would greatly appreciate any help!!