[Tutor] Why is this only catching one occurance?

Chris Hengge pyro9219 at gmail.com
Fri Oct 27 21:07:50 CEST 2006


Thats for this very humorous reply =D

On 10/26/06, Luke Paireepinart <rabidpoobear at gmail.com> wrote:
>
> Chris Hengge wrote:
> > Here is my code:
> > for unWantedItem in directoryList:
> >             try:
> >                 if "hex" in unWantedItem.lower():
> >                     if not "bmc" in unWantedItem.lower():
> >                        print unWantedItem + " removed!"
> >                        directoryList.remove(unWantedItem)
> >
> > This only seems to loop through once, and removes 1 of 2 occurances
> > from this list that should be captured. Should "for" keep the list
> > going through each instance?
> >
> You're removing stuff from something you're iterating over!
> *slaps your fingers with a ruler*
> Make a copy of the list!
> HTH,
> -Luke
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061027/ae1a548e/attachment.html 


More information about the Tutor mailing list