I'm just starting out in Python and I got across this question. Examines an array of integers and eliminates all duplication of values. The distinct integers are all moved to the left part of the array
I'm trying to find all the duplicate entries in the array, delete them, and move the rest of the items towards left.
This is the code I've written, and I just can't figure out what's wrong and how its getting out of index, I tried writing it in C++ and it works fine. Can anybody please help me and explain to me how the its getting out of index.
array = [2,2,3,5,2,5,6,2,4,8,3,36,8,2]
for i in range(len(array)-1,-1,-1):
for j in range(0,i):
if(array[j]==array[i]):
del array[i]
print(array)
The expected output is
[2, 3, 5, 6, 4, 8, 36]
[2, 3, 5, 6, 4, 8, 36]?