>>> files=os.listdir(".") >>> files.sort() >>> print files ['1.txt', '10.txt', '11.txt', '2.txt', '3.txt'] >>> files.sort(key= lambda x:int(x[:-4])) >>> print files ['1.txt', '2.txt', '3.txt', '10.txt', '11.txt']