0

I have found a better way to do this, so that's not my main issue. I'm trying to just determine why what I have below here doesn't work and I just can't. Any advice?

def removeDuplicates(l):
    for item in l:
        while l.count(item) > 1:
            l.remove(item)
    return l

Thanks!

Vasilis G.
  • 7,556
  • 4
  • 19
  • 29
  • 2
    Mutating the list while iterating over it. Also, strange indentation. – jarmod Feb 17 '22 at 19:10
  • I figured that was the problem, that I was changing the list while editing it, but it seemed to work for a few test cases I tried. Why exactly doesn't it work? – Glenn Habibi Feb 18 '22 at 16:10
  • Some related content [here](https://stackoverflow.com/questions/1207406/how-to-remove-items-from-a-list-while-iterating). – jarmod Feb 18 '22 at 16:16

0 Answers0