for unWantedItem in directoryList[,,-1]:
but I get an error:
for unWantedItem in directoryList[,,-1]:
^
SyntaxError: invalid syntax
I understand what you are saying to do, and it makes sense, but I'm not sure how to impliment it.
On 10/27/06, Bob Gailer <
[EMAIL PROTECTED]> 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?
"for" goes thru the list accessing item[0], item[1], item[2], etc. Let's
say "for" is on item[1] and you remove item[1]. All the subsequent items
"move left", so item[2] becomes item[1], item[3] becomes item[2], etc.
"for" then steps to item[2], skipping the original item[2].
There are several ways around this. The easiest is to process the list
backwards: for unWantedItem in directoryList[,,-1]:
--
Bob Gailer
510-978-4454
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor