What is the function in Python that sort files by extension?
Question: 
    import os
    import string
    os.chdir('C:\Python27')
    x=os.listdir('C:\Python27')
    
    y=[f for f in os.listdir(dirname)
        if os.path.isfile(os.path.join(dirname, f))]
    
    for k in y:
        fileName, fileExtension = os.path.splitext(k)
        print fileName,fileExtension
    

And now, I want to sort the files by extension.


Answer: To sort by name, then by extension:

    
    
    y.sort(key=os.path.splitext)
    

It produces the order:

    
    
    a.2
    a.3
    b.1
    

To sort only by extension:

    
    
    y.sort(key=lambda f: os.path.splitext(f)[1])
    

It produces the order:

    
    
    b.1
    a.2
    a.3
    

