os.walk() dirs and files

rtilley rtilley at vt.edu
Wed Feb 8 16:31:23 EST 2006


George Sakkis wrote:

> Or a bit more efficiently (no need to allocate a new list for storing
> files+dirs):
> 
> from itertools import chain
> for root, dirs, files in os.walk(path):
> 	for fs_object in chain(files,dirs):
> 		ADD fs_object to dictionary

I like that! itertools is cool... a bit abstract and computer sciencey, 
but it sure does work in a practical manner :)



More information about the Python-list mailing list