Newbie question about list method remove

news-server.sdd.hp.com Michael.Harp at hp.com
Wed May 5 20:03:44 EDT 2004


Try this,

> >>> li2 =['this.txt', 'that.txt', 'April04', 'more.txt']
> >>> for item in li2[:]: #Make a copy of the list
>             if ".txt" in item:
>                 li2.remove("%s" %item)
> >>> li2
> ['that.txt', 'April04']

Mike

"Sean Berry" <sean_berry at cox.net> wrote in message
news:myemc.69648$Jy3.5301 at fed1read03...
> Why is this:
>
> >>> li2 =['this.txt', 'that.txt', 'April04', 'more.txt']
> >>> for item in li2:
>             if ".txt" in item:
>                 li2.remove("%s" %item)
> >>> li2
> ['that.txt', 'April04']
>
> I would think that 'that.txt' would be removed as well.  Where am I wrong?
>
> TIA
>
>





More information about the Python-list mailing list