En Sat, 17 Mar 2007 03:54:22 -0300, Milton Segura <[EMAIL PROTECTED]>
escribió:
> Hello, I'm trying to exclude files from a list using the following code:
> for item in dirs: if item.find('Software') > -1:
> dirs.remove(item) elif item.find('Images') > -1:
> dirs.remove(item)
> For some reason.. it just won't exclude them.
> I'd like to know why and how to fix it.
Don't iterate over the list and alter it at the same time; the iterator
gets confused.
Iterate over a copy:
for item in dirs[:]:
if item.find(...)
or backwards:
for item in reversed(dirs):
if item.find(...)
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list