I was triying to make a program that can remove any other appearnces of an item in a list but it seems that there is something that I don't understand about loops
list = [3, 2, 1, 4, 2, 3, 2]
list2 = list.copy()
list2.reverse()
l = len(list)
for i in range(l - 1):
for j in range(i+1, l):
if list[i] == list[j]:
h = list[j]
list2.remove(h)
list2.reverse()
print(list2)
the output: [3, 1, 4] expected : [3, 2, 1, 4] (I got it after adding "break" under list2.remove(h))
my question is why is "break" necessary here ? the block under if should have been executed only once even without using "break". in other way when i =1 and j = 4 the if conditon is met so the block is executed removing "2" once from list2 then when i=1 and j=6 "2" is removed again. so why did another "2" get removed ?