The problem with skipping over them is that "walk" would still walk them and their content. If they have a lot of other dirs and files inside then this might end up being time consuming.
Thanks, Ray Neil Cerutti wrote: > On 2006-11-17, Rares Vernica <[EMAIL PROTECTED]> wrote: >> Sorry for not being clear from the beginning and for not using >> clear variable names. >> >> Problem context: >> >> import os >> dirs_exclude = set(('a', 'b', 'e')) >> for root, dirs, files in os.walk('python/Lib/email'): >> # Task: >> # delete from "dirs" the directory names from "dirs_exclude" >> # case-insensitive >> >> The solution so far is: >> >> for i in xrange(len(dirs), 0, -1): >> if dirs[i-1].lower() in dirs_exclude: >> del dirs[i-1] >> >> I am looking for a nicer solution. > > I'd probably just skip over those dirs as I came them instead of > troubling about mutating the list. Unless the list is needed in > more than one place. > -- http://mail.python.org/mailman/listinfo/python-list