diff --git a/marimo/_utils/files.py b/marimo/_utils/files.py index 9f3c7db7d5e..076360c29cb 100644 --- a/marimo/_utils/files.py +++ b/marimo/_utils/files.py @@ -6,15 +6,11 @@ from pathlib import Path from typing import Union +_num_split = re.compile("([0-9]+)").split -def natural_sort(filename: str) -> list[Union[int, str]]: - def convert(text: str) -> Union[int, str]: - return int(text) if text.isdigit() else text.lower() - - def alphanum_key(key: str) -> list[Union[int, str]]: - return [convert(c) for c in re.split("([0-9]+)", key)] - return alphanum_key(filename) +def natural_sort(filename: str) -> list[Union[int, str]]: + return [int(c) if c.isdigit() else c.lower() for c in _num_split(filename)] def get_files(folder: str) -> Generator[Path, None, None]: