0

I have a weird problem, so basically when I write this:

def deletex():
    s= "The quick red fox jumped over the lazy dog."
    t= s.split()
    for x in t:
            t.remove(x)

    return t
print deletex()

So I don't get nearly what I expected, it removes every other word instead of every single one.

Why?

I can get around it with appending to a different list, but I want it to work this way too, since lists are supposed to be mutable. Also I noticed when I try to do x.capitalize() it doesn't work without appending to an empty list.

  • 4
    you should not be modifying an iterator while iterating through it. – MK. Sep 25 '13 at 19:11
  • Also, just for future, `list.clear()` will delete everything in the list. No need for a multi-line function. –  Sep 25 '13 at 19:14

0 Answers0