sort a list of files

Ryan Forsythe ryanf at cs.uoregon.edu
Sat May 6 22:31:37 CEST 2006


Gary Wessle wrote:
> Hi
> 
> I am trying to print out the contents of a directory, sorted.
...
> if I remove ".sort()" at the end of line 6 I get an unsorted list of
> files, if I leave it I get None. who do I fix this?

`blah.sort()` sorts in-place and returns None. You probably want 
sorted(blah):

 >>> a = [3, 1, 4, 1, 5, 9]
 >>> sorted(a)
[1, 1, 3, 4, 5, 9]
 >>> a
[3, 1, 4, 1, 5, 9]
 >>> a.sort()
 >>> a
[1, 1, 3, 4, 5, 9]

--
Ryan Forsythe



More information about the Python-list mailing list