Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Sort by Extension by lisovsky
def sort_by_ext(files: list[str]) -> list[str]:
files.sort(key = lambda file: "#" + file if (file.startswith(".") and file.count(".") == 1) or file.endswith(".") else "#".join(file.rsplit(".", maxsplit = 1)[::-1]))
return files
print("Example:")
print(sort_by_ext(["1.cad", "1.bat", "1.aa", "0.cad"]))
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",
]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Sept. 14, 2022
Comments: