Light Mode
Dark Mode
Sort by Extension
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: Oct. 9, 2022, 3:40 a.m.
Updated: Oct. 9, 2022, 6:33 a.m.
0
10
User avatar
zurain2001