2

I have the next piece of code which counts unique elements in list and remove those elements from that list:

l = [1, 2, 3, 4, 5]
for i in l:
    if l.count(i) == 1:
        l.remove(i)
print l

However, after list modification by l.remove(i) I still have elements in the list: [2, 4]

My question is why list.remove() operation doesn't delete all elements if all of them are unique and amount per each one will be 1 during each iteration?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user54
  • 573
  • 2
  • 7
  • 22

0 Answers0