Simple sort for lists?

Alex Martelli aleax at aleax.it
Thu Nov 21 06:32:36 EST 2002


R. Arens wrote:

> Hi, I'm using os.path.walk to walk through directories and join
> ordered files in the directories into one large file. Problem is,
> os.path.walk doesn't process the files in order, due to the way
> os.path.walk sends the filenames to the visit function. Does Python
> provide a method to sort the list of filenames provided by
> os.path.walk?

You can easily sort a list, in any way you have obtained it, by
calling the sort method of the list -- it gets sorted in-place.
So, if x is bound to a list object, that list object will be
sorted after you've called x.sort().


Alx




More information about the Python-list mailing list