Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Double sorted solution in Clear category for Sort by Extension by Striga
from typing import List
def sort_by_ext(files: List[str]) -> List[str]:
return sorted(sorted(files), key=(lambda x:
x.split('.')[-1] if x.rfind('.') > 0 and x[-1] !='.'
else ('.'+x if x[-1] == '.' else x)))
if __name__ == '__main__':
assert sort_by_ext(['1.cad', '1.bat', '1.aa']
) == ['1.aa', '1.bat', '1.cad']
assert sort_by_ext(['1.cad', '1.bat', '1.aa', '2.bat']
) == ['1.aa', '1.bat', '2.bat', '1.cad']
assert sort_by_ext(['1.cad', '1.bat', '1.aa', '.bat']
) == ['.bat', '1.aa', '1.bat', '1.cad']
assert sort_by_ext(['1.cad', '1.bat', '.aa', '.bat']
) == ['.aa', '.bat', '1.bat', '1.cad']
assert sort_by_ext(['1.cad', '1.', '1.aa']) == ['1.', '1.aa', '1.cad']
assert sort_by_ext(['1.cad', '1.bat', '1.aa', '1.aa.doc']
) == ['1.aa', '1.bat', '1.cad', '1.aa.doc']
assert sort_by_ext(['1.cad', '1.bat', '1.aa', '.aa.doc']
) == ['1.aa', '1.bat', '1.cad', '.aa.doc']
Oct. 5, 2020