NOTE: I do not want to use
del
I am trying to understand algorithms better which is why I want to avoid the built-in
del
statement.
I am populating a list of 10 randomly generated numbers. I then am trying to remove an item from the list by index, using a for
loop:
if remove_index < lst_size:
for value in range(remove_index, lst_size-1):
lst[value] = lst[value+1]
lst_size -= 1
Everything works fine, except that the loop is adding the last item twice. Meaning, if the 8th item has the value 4, it will add a 9th item also valued 4. I am not sure why it is doing this. I still am able to move the value at the selected index (while moving everything up), but it adds on the duplicate.