Help sorting a list by file extension
Peter A. Schott
paschott at no.yahoo.spamm.com
Thu Aug 11 20:06:17 EDT 2005
Trying to operate on a list of files similar to this:
test.1
test.2
test.3
test.4
test.10
test.15
test.20
etc.
I want to sort them in numeric order instead of string order. I'm starting with
this code:
import os
for filename in [filename for filename in os.listdir(os.getcwd())]:
print filename
#Write to file, but with filenames sorted by extension
Desired result is a file containing something like:
C:\MyFolder\test.1,test.001
C:\MyFolder\test.2,test.002
C:\MyFolder\test.3,test.003
C:\MyFolder\test.4,test.004
C:\MyFolder\test.10,test.010
C:\MyFolder\test.15,test.015
C:\MyFolder\test.20,test.020
I need to order by that extension for the file output.
I know I've got to be missing something pretty simple, but am not sure what.
Does anyone have any ideas on what I'm missing?
Thanks.
-Pete Schott
More information about the Python-list
mailing list