I have to decrease my range in every loop end. here is an example code:
for i in range(len(array)):
if (array[0][5] == array[i][5]):
array2.append(array[0])
array3.append(array[i])
array.remove(array[i])
array.remove(array[0])
this throws an error that list index out of range so I tried to add i-=1 in every remove functions end but it doesn't fix it.
I couldnt fixed it so I tried to fix this problem in another way.
n = len(array) # maybe it could be len(array) -1 for the index problem but I also tried that it didnt work.
k = len(array)-1
for n in range(n, 0, -2):
if (array[0][5] == array[n][5]):
array2.append(array[0])
array3.append(array[n])
array[k] = array[n]
array[k-1] = array[0]
k -= 2
I thought that if I do that, I shouldn't compare the last 2 values after the loop but the error is the same error : list index out of range
Solving this problem with NOT starting loop from the end is my first priority.
I want to match 2 values from 2 different arrays when arrays 2's elements equals to each other and then I have to out them off from the list because when I match 2 values I don't need them anymore. But there is a problem right there which is when I remove the element from the list, I can not reach all the values in the list because of the iteration still during.
array1 = [0,1],[0,2],[0,2],[0,2],[0,1],[0,3]
array2 = [0,1],[0,1],[0,1],[0,2],[0,2],[0,3]
for i in range(len(array1)):
for j in range(len(array2)):
if(array1[i][1] == array2[j][1]):
temp_arr2.append(array1[i])
temp_arr1.append(array2[j])
array1.remove(array1[i])
array2.remove(array2[j])