def sort_by_ext(files: list[str]) -> list[str]:
# your code here
return sorted(files, key=sort_key)
def sort_key(file) -> tuple[str, str]:
name, dot, ext = file.rpartition(".")
return (("", ext),(ext, name))[bool(name)]
I don't understand what the [bool(name)] does in the last line of code. What does it do and why is it important?
Thank you!
Created at: 2022/10/09 03:40; Updated at: 2022/10/09 06:33