[Tutor] Question regarding list editing (in place)

Kent Johnson kent37 at tds.net
Tue Feb 5 20:43:51 CET 2008


bob gailer wrote:
> dirs = [dir for dir in dirs if not dir.startswith(u'.')]

Except to filter the directory list for os.walk() you have to modify the 
list in place. Use this:
dirs[:] = [dir for dir in dirs if not dir.startswith(u'.')]

Kent


More information about the Tutor mailing list